Skip to content

Instantly share code, notes, and snippets.

@pranavrajs
Created October 7, 2017 17:56
Show Gist options
  • Save pranavrajs/100da1f43683120f684d7b5c78c01031 to your computer and use it in GitHub Desktop.
Save pranavrajs/100da1f43683120f684d7b5c78c01031 to your computer and use it in GitHub Desktop.
Response interceptor
const parseErrorCode = (error) => {
if (error.response) {
if (error.response.status === 401) {
// If auth failed
} else if (error.response.status === 500) {
// If server failed
} else if (error.response.status === 422) {
// If request params are errored
} else {
// Anything else
}
} else {
// Something happened in setting up the request that triggered an Error
}
// Do something with request error
return Promise.reject(error);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment