Guard callback errors by emitting a statusCode and don't bother any longer.
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Express Status Guard

Inspirated by Haskells monad guards, this middleware frees you from the burden of repetitive error handling in your callbacks and lets you focus on your business logic.

Just app.use(guard()).

Before (err, data) {
  if (err) return res.send(500);, function (err, data2, data3) {
    if (err) return res.status(500).send('Uh! Fail.');, data3, function (err, data4) {
      if (err) return res.status(500).json({error: 'meeh'});
      res.json({result: data4});

After, function (data) {, res.guard(500, 'Uh! Fail.', function (data2, data3) {, data3, res.guard(500, {error: 'meeh'}, function (data4) {
      res.json({result: data4});