Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
47
rated 0 times [  50] [ 3]  / answers: 1 / hits: 5342  / 2 Years ago, fri, february 18, 2022, 12:00:00

Our Vue application had some problems and I noticed in Sentry logs that probably the network has been unreliable:


Error: Network Error
Error: Request aborted

I would like to show warning to the user, but couldn't figure out how to do it. I tried to catch these errors using Axios request interceptor, but they didn't work. Has anyone accomplished this?


EDIT:


This is the interceptor that didn't work. I also have a response interceptor to catch 403 and it works perfectly.


axios.interceptors.request.use(undefined, (err) => {
// Never gets here for network errors
return new Promise((resolve, reject) => {
throw err;
});
});

More From » vue.js

 Answers
3

Did you try?


return Promise.reject(error);

like this:




axios.interceptors.response.use(function (response) {
// Any status code that lie within the range of 2xx cause this function to trigger
// Do something with response data
return response;
}, function (error) {
// Any status codes that falls outside the range of 2xx cause this function to trigger
// Do something with response error
return Promise.reject(error);
});




reference: https://axios-http.com/docs/interceptors


[#351] Wednesday, February 9, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
parker

Total Points: 259
Total Questions: 109
Total Answers: 97

Location: Zambia
Member since Thu, Jun 25, 2020
4 Years ago
;