Created
March 28, 2018 17:07
-
-
Save OtavioBraga/b2d465fb43083cbb719e2503149a5bbd to your computer and use it in GitHub Desktop.
Axios interceptor for responses
This file contains hidden or 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
axios.interceptors.response.use((response) => { | |
// Do something with response data | |
return response; | |
},(error) => { | |
// Do something with response error | |
// You can even test for a response code | |
// and try a new request before rejecting the promise | |
if (error.response.status === 401) { | |
const requestConfig = error.config; | |
return axios(requestConfig); | |
} | |
return Promise.reject(error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment