Created
October 7, 2017 17:56
-
-
Save pranavrajs/100da1f43683120f684d7b5c78c01031 to your computer and use it in GitHub Desktop.
Response interceptor
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
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