Created
September 18, 2023 08:02
-
-
Save moaoa/8f8c9c77de0e72c79c76ef21b60405d5 to your computer and use it in GitHub Desktop.
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/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