[OK]を私持って、次のコード res.end
router.route('/getParkData/:parkLocationId').get(function(req, res){
var id = req.params.parkLocationId;
var parkdata = {};
parkInfo(id).then(function(data){
if(data.parking_type == 'FREE')
{
var json = JSON.stringify({
"error" : null,
"result" : null,
"message" : "free",
"error_code" : null
});
res.end(json);
}
else
return getTwowheelers(id)
}).then(function(data){
if(data[0].parking_type)
{
parkdata.parkingType = data[0].parking_type;
}
else
{
parkdata.parkingType = "paid";
}
if(data.length > 0)
{
parkdata.tw = data[0].rate.tw[0];
}
else
{
parkdata.tw= 0;
}
return getFourwheelers(id);
}).then(function(data){
console.log(data.length);
if(data.length > 0)
{
parkdata.fw = data[0].rate.fw[0];
}
else
{
parkdata.fw = 0;
}
res.json(mResponse.response(null, parkdata, "Success",200));
}).catch(function(err){
res.json(mResponse.response(null, null, "No data!",500));
});
});
だから私は条件をチェックし、正常に動作respons.Itsを終了することにより、簡単な修正をしていたが、私はこのエラーを取得します。条件
if(data.parking_type == 'FREE')
は、それが持つレスポンス意志真であるとき
Unhandled rejection Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:344:11)
at ServerResponse.header (C:\zoyoapp\node_modules\express\lib\response.js:719:10)
のでres.endは、私はそれがこのエラー
コードを正しくインデントしてください。 – str
あなたのコードは適切な中括弧が一致していないと不完全なようですが、完全なコードを投稿できますか? – Sridhar
@Sridharちょっと編集しました –