Skip to content

Instantly share code, notes, and snippets.

@RobyCigar
Created July 16, 2022 09:44
Show Gist options
  • Save RobyCigar/e70163030d97197497804b254033f9f0 to your computer and use it in GitHub Desktop.
Save RobyCigar/e70163030d97197497804b254033f9f0 to your computer and use it in GitHub Desktop.
Error handling for axios
axios.get('/api/xyz/abcd')
.catch(function (error) {
if (error.response) {
// Request made and server responded
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} else if (error.request) {
// The request was made but no response was received
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment