Reputation: 3040
I have the following in my typescript file
async createProduct(data) {
return await axios.post(request).catch(error => {
console.log('error'.bgRed.white.bold, error)
});
}
that error looks like this when logged
I need to single out the error from the outside api which looks like this
return error.title
here is the full response https://jsoneditoronline.org/#left=cloud.c584e42736664e9595fcfd8bb9c668a4
Upvotes: 1
Views: 497
Reputation: 354
Try const errorObject = JSON.parse(error.config.data)
.
If the syntax in the string is correct, you should be able to access the title as usual errorObject.title
Upvotes: 1