Created
July 16, 2022 09:44
-
-
Save RobyCigar/e70163030d97197497804b254033f9f0 to your computer and use it in GitHub Desktop.
Error handling for axios
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
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