Skip to content

Instantly share code, notes, and snippets.

@paolobueno
Last active February 2, 2017 18:49
Show Gist options
  • Select an option

  • Save paolobueno/61793824d22de69823d9d459adf6d4b5 to your computer and use it in GitHub Desktop.

Select an option

Save paolobueno/61793824d22de69823d9d459adf6d4b5 to your computer and use it in GitHub Desktop.
Does express global error handler works with `throw`?
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