防止用户在node.js中看到错误

防止用户在node.js中看到错误,node.js,error-handling,coffeescript,express,Node.js,Error Handling,Coffeescript,Express,在node.js中使用express.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 EXCEP

node.js
中使用
express.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
时,
错误:出现了错误
,并显示了错误的堆栈跟踪。如果我将所有路由放在
try/catch
-块中,也会发生同样的情况


如何防止这种情况发生?

查看本页了解如何抑制错误输出:


成功了。不过,我不得不在我的路由之后放置错误处理块,这有点出乎意料。