At this moment i'm using a response interceptor instance.interceptors.response.use
for global error handling. In that function i'm redirecting in case of a 404, i'm clearing the storage in case of a 401 etc. Which works fine :)
Except now I've got a spot where i want to handle the 404 error differently, but a simple try/catch or a .catch won't work since the axios interceptor intercepts the response and redirects immediately.
Whats the best practice in this situation?
- Not using the interceptor for global error handling? (but then what? call a handleError kind of function after every request except this one?)
- Temporary turn it off somehow
- Pass an ignore404 option or something with the axios request (although I use a function per request so i can't do this really simple)
- What would be the best, but i'm not sure how is that axios is always doing some global error reporting except when you catch it yourself. And at that point at the bottom of the catch i could let the global error handler do it's job anyway if i want to
My interceptor:
function onResponseRejected(error) {
const { response } = error;
if (!response) return Promise.reject(error); // network error, not axios related
const { status } = response;
const { errors } = response.data;
if (status === 403) {
router.push({ name: '403' });
} else if (status === 404) {
router.push({ name: '404' });
}
....
....
My axios requests
export const fetch = (some) => {
return get(`some/${someId}/url/`)
}
My application usage of a request
const response = fetch(this.$route.params.connectorId, this.$route.params.mapperId).catch(() => {
console.log('At this moment the request will be redirected to another route...');
});