Skip to content

Instantly share code, notes, and snippets.

@kianaditya
Last active April 1, 2020 07:21
Show Gist options
  • Save kianaditya/d12bdd0f373e92df706f86098f595539 to your computer and use it in GitHub Desktop.
Save kianaditya/d12bdd0f373e92df706f86098f595539 to your computer and use it in GitHub Desktop.
Axios reponse interceptor example
http.interceptors.response.use(
response => {
return response;
},
error => {
if (error.response) {
switch (error.response.status) {
case 500:
return (document.location.href =
process.env.REACT_APP_CLIENT_URL + "/500");
case 404:
return (document.location.href =
process.env.REACT_APP_CLIENT_URL + "/404");
default:
return Promise.reject(error);
}
}
return Promise.reject(error);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment