Node Express发送错误待定

时间:2013-11-22 13:42:12

标签: node.js express http-status-code-404 send

我在Express中发送'404'响应时遇到问题。我有以下代码:

app.get("/oneimage/:id", function(req, res) {
  Images.findById(req.params.id, function(error, results) {
    if (error) {
        res.json(error, 400);
    } else if (!results) {
         res.send(404, 'No Logo Found ')
    } else {
        res.contentType(results.imageType);
        res.end(results.image.buffer, "binary");
    }
  });
});

在else if中,如果没有结果发送(404)挂起,我可以看到请求保持挂起状态并且永不超时。

我尝试用以下代码替换发送:

  res.wrtieHead(404, { 'Content-Type': 'text/plain' });
  res.write('Not found!');
  res.end();

我使用的是Chrome版本30.0.1599.114。我原本以为这可能是Chrome问题,但我在Firefox中看到了相同的行为。

有什么想法吗?

0 个答案:

没有答案