Seeing error message from network tab, but not in the try/catch console.log(error)

Viewed 795

I am working on the front-end part of a project, and the backend is done, basically when a condition is met, the backend will send 409 conflict and a specific error message, and my job is to capture that error message and let that to be displayed on the front-end.

But I couldn't get the error message in the try-catch block, and only seeing the error message in the Network tab of Chrome.

Here's my try-catch front end code

try{
            const response = await this.request({
                path: `/api/xxx/xxx/{xxx}/xx`.replace(`{${"xxx"}}`, xx(String(requestParameters.terminalId))),
                method: 'PUT',
                headers: headerParameters,
                query: queryParameters,
                body: UpdateTerminalDataPortRequestDtoToJSON(requestParameters.updateTerminalDataPortRequestDto),
            }, initOverrides);
        }
        catch(e){
            console.log("error message")
            console.error(e)
        }

and here is what the Network Tab enter image description here

and here is what the console log error look like: enter image description here

How can I get the same error message as the one showing in the Networks?

Thanks in advance....any comment would be appreciated

1 Answers

Solved it by accessing err.response through catch

.catch(function (err) {
    console.log(err.response)
})
Related