How would I keep uncaught errors from being sent to the users when I use express.js
in node.js
?
Let's say that I have the following route set up:
app.get "/err", (req, res) ->
throw new Error "Something went wrong"
res.send "Hello World", 200
And to handle my exceptions:
process.on "uncaughtException", (err) ->
console.log "OH NOES: UNCAUGHT EXCEPTION"
console.log err.message, err.stack
process.exit(1) #Exit with error
Still, when I visit the /err
in my browser, Error: Something went wrong
is shown along with a stack trace of the error. The same thing occurs if I put all my routes inside a try/catch
-block.
How do I prevent this?
Check out this page for how to suppress the error output: