ExpressJS:自定义错误模块无法识别此错误

ExpressJS: The custom error module does not recognize this error

我是 运行 一个 Express.JS 后端,如果用户尝试使用已经注册的电子邮件注册,我将其设置为 return 带有自定义消息的 422 错误在使用中,像这样:

const existingUser = await User.findOne({ email: email });
    if (existingUser) {
        return res.status(422).send({ error: 'Email is already in use' });
    }

然而,我在前端看到的响应是这样的:

"response":{"data":"The custom error module does not recognize this error.","status":422,"statusText":"Unprocessable Entity"

显然,有些东西正在改变到前端的错误。

我 运行 现在在本地进行开发,但生产部署到 Azure,所以我有一个 Web.config 文件和一个 iisnode.yml 文件。我已将此代码添加到前者,以确保它不会导致问题:

<system.webServer>
  <httpErrors existingResponse="PassThrough">
  </httpErrors>
</system.webServer>

我该如何解决这个问题?

不确定,但以下内容应该有效。

return res.status(422).send('Email is already in use');

设置 <httpErrors> 后对我有用,如下所示:

浏览器输出: