This code is using axios and its error object, but is wrong because the key not exist,
const axios = require('axios');
axios.get('http://w3c.org/error_here').then(response => {
console.log(response.data);
}).catch(error => {
console.log(error.Error) // not exist
});
This other code is working fine, but there are no clues about how to solve the problem to output only the error message (supposed before error.Error
).
const axios = require('axios');
axios.get('http://w3c.org/error_here')
.then(response => {
console.log(response.data);
}).catch(error => {
delete error.request
delete error.config
delete error.response
console.log(error) // a string here!
console.log(JSON.stringify(error)) // where??
});
The first console.log()
output is a string
Error: Request failed with status code 404 ...
the second is an empty object,
{}
So, where the string (or the object)? How to do something as console.log(error.Error)
to show only the error message?