Need a way to handle rejection/resolve after request is completed
Is your feature request related to a problem? Please describe.
A problem: Currently axios contains interceptors, which are executed before standard handlers. What we want to do: we want to have standard error handler, which will execute only if there is no local handler
Describe the solution you'd like
import Toast from 'toast';
const axiosInstance = axios.create();
axiosInstance.defaultReject((error) => {
if (['401', '403', '404'].includes(error.status.code)) {
Toast(error);
}
// in case we don't expect that issue at all we fail-fast
return Promise.reject();
})
// guess also makes sense for some cases
axiosInstance.defaultResolve();
axiosinstance.get('whatever').catch((error) => {
if (error.status.code === 404) {
// show user that something was not found
}
// axiosInstance.defaultReject will execute
return Promise.reject(error);
})
// in case of error axiosInstance.defaultReject will execute
axiosinstance.get('whatever-another');
axiosinstance.get('whatever-another-smoething).catch((error) => {
// only that handler will execute, and not axiosInstance.defaultReject
});
Describe alternatives you've considered
Currently only 1 alternative was found - copypaste "standardhandler" everywhere in catch
Additional context
no
@Hulkmaster Can response interceptor solve your issue ?
https://axios-http.com/docs/interceptors
No, i need default handle which will run only if there is no try/catch, not always
I am working on this feature. Can I be an assignee ?
i guess we need to ask contributors to put you there
I made a PR but I don't know how to link it to this issue
you can just leave link to pr here, github will automatically mention it here
you can also just mention current issue in your PR
https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword
https://github.com/axios/axios/pull/4055