简体   繁体   English

从网络选项卡中看到错误消息,但在 try/catch console.log(error) 中没有

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

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.我在做一个项目的前端部分,后端搞定了,基本上满足一个条件,后端就会发送409冲突和具体的错误信息,我的工作就是捕捉那个错误信息,让那个显示在前端。

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.但我无法在 try-catch 块中收到错误消息,只能在 Chrome 的“网络”选项卡中看到错误消息。

Here's my try-catch front end code这是我的 try-catch 前端代码

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这是网络选项卡在此处输入图像描述

and here is what the console log error look like:这是控制台日志错误的样子: 在此处输入图像描述

How can I get the same error message as the one showing in the Networks?如何获得与网络中显示的错误消息相同的错误消息?

Thanks in advance....any comment would be appreciated在此先感谢....任何评论将不胜感激

Solved it by accessing err.response through catch通过catch访问err.response解决了

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM