Last active
February 2, 2017 18:49
-
-
Save paolobueno/61793824d22de69823d9d459adf6d4b5 to your computer and use it in GitHub Desktop.
Does express global error handler works with `throw`?
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
| var express = require('express'); | |
| var Promise = require('bluebird'); | |
| var app = express(); | |
| var router = express.Router(); | |
| router.get('/error', function(req, res, next) { | |
| return new Promise(function() { | |
| throw new Error('boom'); | |
| }).catch(next); | |
| }); | |
| router.get('/errorish', function(req, res, next) { | |
| return new Promise(function() { | |
| throw 'boom'; | |
| }).catch(next); | |
| }); | |
| app.use('/router', router); | |
| app.use(function(err, req, res, next) { | |
| console.error('hello from your favorite error handler!'); | |
| res.status(500).send(err.message || err); | |
| }); | |
| app.listen(8888); | |
| // curl http://localhost:8888/router/error | |
| // curl http://localhost:8888/router/errorish |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment