0

express.js当我使用in时,如何防止未捕获的错误被发送给用户node.js

假设我设置了以下路线:

app.get "/err", (req, res) ->
  throw new Error "Something went wrong"
  res.send "Hello World", 200

并处理我的异常:

process.on "uncaughtException", (err) ->
  console.log "OH NOES: UNCAUGHT EXCEPTION"
  console.log err.message, err.stack
  process.exit(1) #Exit with error

不过,当我/err在浏览器中访问时,Error: Something went wrong会显示错误的堆栈跟踪。如果我将所有路线都放在try/catch-block 中,也会发生同样的事情。

我该如何防止这种情况?

4

1 回答 1

0

查看此页面以了解如何抑制错误输出:

http://expressjs.com/guide.html#error-handling

于 2012-11-12T17:52:37.237 回答