Skip to content

omrilitov/api-error-handler

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

api-error-handler

NPM version Build status Test coverage Dependency Status License Downloads Gittip

An error handler for JSON APIs, meant to be used with http-errors-style errors.

Example

var errorHandler = require('api-error-handler');

var api = new express.Router();
api.get('/users/:userid', function (req, res, next) {

});

api.use(errorHandler());

app.use('/api', api);

API

.use(errorHandler([options]))

Returns middleware that handle errors.

Options

The errorHandler function takes an option options object that may contain any of the following keys:

log

The log option, if supplied, is called as log(err, req, res) when errors with status 500 and above occur.

Errors

4xx errors are exposed to the client. Properties exposed are:

  • message
  • type
  • name
  • code
  • status

5xx errors are not exposed to the client. Instead, they are given a generic message as well as the type.

About

Express error handlers for JSON APIs

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%