2.4.1 • Published 7 years ago

meanie-express-error-handling v2.4.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

meanie-express-error-handling

npm version node dependencies github issues codacy

A collection of error types, handlers and middleware for use with Meanie Express Seed projects

Meanie

Installation

You can install this package using npm.

npm install meanie-express-error-handling --save

Configuration

//Load library
const errors = require('meanie-express-error-handling');

//Define some custom middleware
const myHandler = function(error, req, res, next) { ... };

//Register it with the error handler
errors.register('my-handler', myHandler);

//Specify default middleware stack to use
errors.use([
  'normalize', 'track-with-sentry', 'my-handler', 'log-to-console',
]);

Usage

Load stack of pre-registered error handling middleware:

const stack = errors.middleware();

Use it as express middleware:

stack.forEach(handler => app.use(handler));

Run an error through error handling middleware stack:

someRoute(req, res, next) {
  doSomething()
    .then(() => {

      //End response
      res.end();

      //Do something else async which won't be part of the request
      //error handling stack, but catch and process the errors anyway.
      doSomethingElse()
        .catch(error => errors.handler(error, req));
    })
    .catch(next);
}

Use some of the pre defined error types:

//Load error
const BadRequestError = errors.BadRequestError;

//Use in route
someRoute(req, res, next) {
  if (somethingBad()) {
    return next(new BadRequestError('Bad things'))
  }
  next();
}

See the Meanie Express Seed for usage.

Issues & feature requests

Please report any bugs, issues, suggestions and feature requests in the meanie-express-error-handling issue tracker.

Contributing

Pull requests are welcome! If you would like to contribute to Meanie, please check out the Meanie contributing guidelines.

Credits

License

(MIT License)

Copyright 2016-2017, Adam Reis

2.4.1

7 years ago

2.4.0

7 years ago

2.3.1

7 years ago

2.3.0

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.8.2

7 years ago

1.8.1

7 years ago

1.8.0

8 years ago

1.7.0

8 years ago

1.6.1

8 years ago

1.6.0

8 years ago

1.5.1

8 years ago

1.5.0

8 years ago

1.4.1

8 years ago

1.3.0

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago