Skip to content

Instantly share code, notes, and snippets.

@OtavioBraga
Created March 28, 2018 17:07
Show Gist options
  • Save OtavioBraga/b2d465fb43083cbb719e2503149a5bbd to your computer and use it in GitHub Desktop.
Save OtavioBraga/b2d465fb43083cbb719e2503149a5bbd to your computer and use it in GitHub Desktop.
Axios interceptor for responses
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