Skip to content

Instantly share code, notes, and snippets.

@tianp
Created February 27, 2015 09:21
Show Gist options
  • Save tianp/8ae5bfd320fe35db6f82 to your computer and use it in GitHub Desktop.
Save tianp/8ae5bfd320fe35db6f82 to your computer and use it in GitHub Desktop.
Node Restify uncaughtException handler
// Extracted from https://gentlenode.com/journal/node-3-restify-cheatsheet/44
server.on( 'uncaughtException', function ( request, response, route, error ) {
// Emitted when some handler throws an uncaughtException somewhere in the chain.
// The default behavior is to just call res.send(error), and let the built-ins in restify handle transforming,
// but you can override to whatever you want here.
if ( process.env.NODE_ENV == 'production' ) {
var responseMessage = {
message: "We had a problem with our server. Try again later."
}
return response.json( 500, responseMessage )
}
response.send( error )
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment