Skip to content

Instantly share code, notes, and snippets.

@jeffkole
Created December 18, 2014 23:52
Show Gist options
  • Save jeffkole/070d621839a042bb3db4 to your computer and use it in GitHub Desktop.
Save jeffkole/070d621839a042bb3db4 to your computer and use it in GitHub Desktop.
router.get('/', function (request, response, next) {
if (request.query.next) {
// Properly handled by Express
next(new Error('Error that I nexted'));
}
else if (request.query['throw']) {
// Properly handled by Express
throw new Error('Error that I threw');
}
else if (request.query.asyncNext) {
// Properly handled by Express
process.nextTick(function () {
next(new Error('Error that I nexted asynchronously'));
});
}
else if (request.query.asyncThrow) {
// Not even seen by Express
process.nextTick(function () {
throw new Error('Error that I threw asynchronously');
});
}
else {
response.status(500).send('FAIL');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment