Created
January 20, 2010 23:18
-
-
Save benw/282399 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
http.createServer(dispatchRequest).listen(port); | |
function dispatchRequest(req, res) | |
{ | |
res.sentinel = new Sentinel(function (e) { | |
// Like a catch() clause that catches callbacks too. | |
// Called if handleRequest throws, or if any of the callbacks | |
// registered by handleRequest throw, or if any of the | |
// callbacks registered by those callbacks throw, etc. | |
res.sendHeader(500, headers); | |
res.sendBody('500 Internal Server Error\n\n' + e.stack); | |
}, function () { | |
// Like a finally clause that runs after all the callbacks, | |
// or after the "catch" callback above. | |
// Just in case handleRequest didn't manage to arrange | |
// for res.finish() to be called. Assumes that | |
// calling res.finish() twice has no bad effects. | |
res.finish(); | |
}); | |
handleRequest(req, res); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment