5.2.0 • Published 4 years ago

@meanie/express-error-handling v5.2.0

Weekly downloads
11
License
MIT
Repository
github
Last release
4 years ago

@meanie/express-error-handling

npm version node dependencies github issues codacy

Error handlers and middleware for use in Express or Meanie Express Seed projects

Meanie

Installation

You can install this package using yarn or npm.

#yarn
yarn add @meanie/express-error-handling

#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);
}

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.

Sponsor

This package has been kindly sponsored by Hello Club, an all in one club and membership management solution complete with booking system, automated membership renewals, online payments and integrated access and light control. Check us out if you happen to belong to any kind of club or if you know someone who helps run a club!

License

(MIT License)

Copyright 2016-2020, Adam Reis

5.2.0

4 years ago

5.1.0

4 years ago

5.0.1

4 years ago

5.0.0

5 years ago

4.0.0

5 years ago

3.3.0

6 years ago

3.2.0

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.0

7 years ago