Omar
Omar

Reputation: 3040

cant parse axios errors

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

enter image description here

I need to single out the error from the outside api which looks like this

enter image description here

How do I single out that part like any other object ie return error.title

Update

here is the full response https://jsoneditoronline.org/#left=cloud.c584e42736664e9595fcfd8bb9c668a4

Upvotes: 1

Views: 497

Answers (1)

torquan
torquan

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

Related Questions