我想用 express 做类似下面的事情。
let error = {errorCode:"1234"}
res.sendStatus(403, {error: error});
在我的前端 javascript 中,我想捕获错误并像这样检查它
getData(mydata).then((data)=> {
console.log(data);
).catch((error)=> {
console.log(error.errorCode);
});
无论出于何种原因,这都没有将 json 发回我的 catch 方法,我想知道为什么以及如何在我发回 403 时发送 json。
最佳答案
使用这个语法
res.status(403).send({errorCode:"1234"});
// or
res.status(403);
res.send({errorCode:"1234"});
关于json - 如何使用 express 从 403 发回 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38879060/