node.js - 节点/快递错误,RangeError [ERR_HTTP_INVALID_STATUS_CODE]:无效状态代码:ENOENT
问题描述
从角度应用程序发布数据时(根据发布请求),我收到此错误。其他请求工作正常。
RangeError [ERR_HTTP_INVALID_STATUS_CODE]:无效状态代码:ENOENT
at ServerResponse.writeHead (_http_server.js:248:11)
at ServerResponse._implicitHeader (_http_server.js:239:8)
at write_ (_http_outgoing.js:650:9)
at ServerResponse.end (_http_outgoing.js:760:5)
at ServerResponse.send (D:\My project\graph final\frontend\FindGrapher-backend-final\node_modules\express\lib\response.js:221:10)
at ServerResponse.json (D:\My project\graph final\frontend\FindGrapher-backend-final\node_modules\express\lib\response.js:267:15)
at D:\My project\graph final\frontend\FindGrapher-backend-final\app.js:42:9
at Layer.handle_error (D:\My project\graph final\frontend\FindGrapher-backend-final\node_modules\express\lib\router\layer.js:71:5)
at trim_prefix (D:\My project\graph final\frontend\FindGrapher-backend-final\node_modules\express\lib\router\index.js:315:13)
at D:\My project\graph final\frontend\FindGrapher-backend-final\node_modules\express\lib\router\index.js:284:7
at Function.process_params (D:\My project\graph final\frontend\FindGrapher-backend-final\node_modules\express\lib\router\index.js:335:12)
at next (D:\My project\graph final\frontend\FindGrapher-backend-final\node_modules\express\lib\router\index.js:275:10)
代码表单后端注册端点
exports.signUp= async (req, res, next) => {
const newUser = new User({
name: req.body.name,
country: req.body.country,
city:req.body.city,
email: req.body.email,
password: req.body.password,
contactNo: req.body.contactNo,
gender: req.body.gender,
});
try {
await newUser.save();
} catch (err) {
const error = new HttpError(
'Signing up failed, please try again.',
500
);
res.json({
message: 'Signing up failed, please try again.',
error: error
});
return next(error);
}
const token = jwt.sign({email: req.body.email}, "token_validator", { expiresIn: "1h"});
res.status(201).json({
message: "SignUp Succsessfull",
token: token
});
};
解决方案
你能把你的渔获改为:
catch (err) {
res.status(500).json({
message: 'Signing up failed, please try again.',
error: error});
}
您收到该错误是因为您没有设置正确的错误状态。
推荐阅读
- reactjs - React PropTypes 和子属性
- c# - 无法成功比较玩家输入和计算机输入 Mastermind
- oracle - 没有oracle账户的oracle数据库vm在哪里获取?
- python - 无法将总列添加到现有的 Indexed DataFrame
- javascript - 如果另一个为真,则有一个功能
- android - 错误:包 android.support.design.button 不存在
- javascript - 如何将 JSON 数据传递给 Node/Express 中的 public/javascripts/X.js?
- unity3d - 如何将运动控制器模型放入新的混合现实工具包中?
- python - 如何在 matplotlib 中计算极坐标图密度
- java - Domino 10 有时不会在 Java 下解码 MIME 标头