Here's the code I'm using for my connection request:
doLogin(this.login).then(response => {
var token = response.data.token;
localStorage.setItem('AUTH_TOKEN', JSON.stringify(token));
this.$router.push({name: 'Devices'});
});
}).catch(error => {
console.log(error.response.data.message);
});
The catch()
part is effective in handling HTTP errors (like 400
, 404
, 403
, etc.). However, when the server is offline, the script throws a net::ERR_CONNECTION_REFUSED
error. Is there a way to handle this error and inform the front-end user that the server is currently offline?
Just in case, here is the doLogin
() function:
function doLogin(data) {
const url = 'http://localhost:3000/authenticate';
return axios.post(url,data);
}