Last active
October 7, 2023 01:44
-
-
Save nemanja947/a71018e659f7d5255ea43c304f8ee108 to your computer and use it in GitHub Desktop.
NProgress implementation with Axios
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add a request interceptor | |
axios.interceptors.request.use(function (config) { | |
// Do something before request is sent | |
NProgress.start(); | |
return config; | |
}, function (error) { | |
// Do something with request error | |
console.error(error) | |
return Promise.reject(error); | |
}); | |
// Add a response interceptor | |
axios.interceptors.response.use(function (response) { | |
// Do something with response data | |
NProgress.done(); | |
return response; | |
}, function (error) { | |
// Do something with response error | |
console.error(error) | |
return Promise.reject(error); | |
}); |
Nice one. But i did progress done on error too.
// Add a request interceptor
axios.interceptors.request.use(function (config) {
// Do something before request is sent
NProgress.start();
return config;
}, function (error) {
// Do something with request error
NProgress.done();
console.error(error)
return Promise.reject(error);
});
// Add a response interceptor
axios.interceptors.response.use(function (response) {
// Do something with response data
NProgress.done();
return response;
}, function (error) {
// Do something with response error
NProgress.done();
console.error(error)
return Promise.reject(error);
});
Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Straight forward
thanks