Skip to content

Instantly share code, notes, and snippets.

@moaoa
Created September 18, 2023 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moaoa/8f8c9c77de0e72c79c76ef21b60405d5 to your computer and use it in GitHub Desktop.
Save moaoa/8f8c9c77de0e72c79c76ef21b60405d5 to your computer and use it in GitHub Desktop.
axios.get('/api/some-endpoint')
.then(response => {
// Handle successful response
console.log(response.data);
})
.catch(error => {
// Handle error
if (error.response) {
// The request was made, and the server responded with a status code
// that falls out of the range of 2xx
console.log(error.response.data); // Backend error message
console.log(error.response.status); // HTTP status code
console.log(error.response.headers); // Response headers
} else if (error.request) {
// The request was made, but no response was received
console.log(error.request); // The XMLHttpRequest object
} else {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message);
}
console.log(error.config); // Axios request configuration
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment