I have an API call using axios. A timeout is set for 2500 millis. What I want is axios to return a value after the timeout so I can notify to the user the request is aborted due to some server or network error.
How I initialized the timeout
const instance = axios.create();
instance.defaults.timeout = 2500;
Below is the function that should return a value after the timeout
_post(url, body, token) {
return new Promise((resolve, reject) => {
instance
.post(url, body, {headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}})
.then(data => {
resolve(data);
})
.catch(error => {
reject(error);
});
});
}
Thank you!