Created
February 27, 2015 09:21
-
-
Save tianp/8ae5bfd320fe35db6f82 to your computer and use it in GitHub Desktop.
Node Restify uncaughtException handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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