Axios: How to get information about the request that caused an error
15 October 2023 (Updated 15 October 2023)
const axios = require('axios')
axios.get('https://some-non-existing-url.com')
.then(response => {
console.log(response.data)
})
.catch(error => {
if (axios.isAxiosError(error)) {
const requestUrl = error.config.url; // Here's the request URL that caused the error
console.log('Error URL:', requestUrl);
} else {
console.error('Some other error occurred:', error.message);
}
})
Tagged:
Axios
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment