node.js - Express - 发送后无法设置标题
问题描述
我知道这是一个经常被问到的问题,但无法弄清楚这里的问题是什么:
router.post('/garage/cart',
app.requirePermission([
['allow', {
users: '@'
}],
['deny', {
users: '*'
}]
]),
function(req, res){
var body = req.body;
if(body.vehicleId
&& body.garageId
&& body.prestationId
&& body.minPrice
&& body.maxPrice)
{
app.services.garage.createVirtualCart(body.vehicleId, body.garageId, function(cartId){
var item = {
quote : {
quoteType : "ONLINE",
carServiceId : body.prestationId,
price : {
minPriceExclTax : parseFloat(body.minPrice),
maxPriceExclTax : parseFloat(body.maxPrice),
}
},
quantity : 1
};
app.services.garage.addItemsToCart(cartId, item, function(){
var partnerCart = app.models.PartnerCart.build();
partnerCart.cart_object = JSON.stringify(item);
partnerCart.cart_createdate = new Date();
partnerCart.cart_accountid = req.account.act_id;
partnerCart.cart_carid = body.vehicleId;
partnerCart.save();
return res.json({
code: 0,
cart: cartId
});
},
function(message){
sendErrorMessage(res, message);
});
},
function(message){
sendErrorMessage(res, message);
});
}else{
sendErrorMessage(res, "Params to create a cart and add an item to it is not suffisiant or not well formed.");
}
}
);
我在addItemsToCart的回调中收到错误。它甚至没有保存记录。但是如果我删除这部分代码:
return res.json({
code: 0,
cart: cartId
});
没有错误,记录已正确保存。
解决方案
推荐阅读
- reactjs - 使用 UserContext.Consumer 包装时,使用元素反应和箭头函数进行字段验证失败
- pine-script - 如何准确地在回测数据上绘制 pine 脚本策略?
- javascript - 收到警告“警告:列表中的每个孩子都应该有一个唯一的“关键”道具。” 当我的组件渲染时
- string - TypeScript > 4.1 固定长度字符串文字类型
- r - order.terms 不会重新排序 sjPlot 的 plot_model 中的术语
- docker - 如何防止 Docker 在执行 RUN 命令时删除中间容器?
- amazon-web-services - 向用户添加 AWS 权限
- reactjs - React.js 中的重父化
- c++ - 使用 SFINAE 将 struct 的引用作为函数模板中的参数转发
- reactjs - 如何在 React 17 中将字符串转换为 JSX