【发布时间】:2017-11-20 07:48:16
【问题描述】:
我正在运行 Express.JS 后端,如果用户尝试使用已在使用的电子邮件进行注册,则将其设置为返回 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>
我该如何解决这个问题?
【问题讨论】:
-
这个问题是否与expressjs有关,如何?您收到的消息似乎来自某些 IIS。你读过这个吗,已经:stackoverflow.com/questions/12908764/…
-
是的,阅读它并将建议的代码添加到 Web.config。问题依然存在。
-
打扰了,再问你一句:这个问题和快递有什么关系?
-
我在后端使用 Express 并从那里返回错误。我不知道为什么错误会在传递到前端的过程中被转换。
标签: node.js azure express iisnode