https://github.com/expressjs/api-error-handler
Express error handlers for JSON APIs
https://github.com/expressjs/api-error-handler
Last synced: 3 months ago
JSON representation
Express error handlers for JSON APIs
- Host: GitHub
- URL: https://github.com/expressjs/api-error-handler
- Owner: expressjs
- License: mit
- Archived: true
- Created: 2014-12-10T21:08:37.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2025-05-14T13:22:38.000Z (8 months ago)
- Last Synced: 2025-09-01T02:30:42.880Z (4 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 101
- Watchers: 10
- Forks: 22
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
> [!CAUTION]
> **This repository is archived and no longer actively maintained.**
>
> We are no longer accepting issues, feature requests, or pull requests.
> For additional support or questions, please visit the [Express.js Discussions page](https://github.com/expressjs/express/discussions).
# api-error-handler
[![NPM version][npm-image]][npm-url]
[![Build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![Dependency Status][david-image]][david-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![Gittip][gittip-image]][gittip-url]
An error handler for JSON APIs, meant to be used with [http-errors](https://github.com/jshttp/http-errors)-style errors.
## Example
```js
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]))
Currently no options.
### 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`.
[gitter-image]: https://badges.gitter.im/expressjs/api-error-handler.png
[gitter-url]: https://gitter.im/expressjs/api-error-handler
[npm-image]: https://img.shields.io/npm/v/api-error-handler.svg?style=flat-square
[npm-url]: https://npmjs.org/package/api-error-handler
[github-tag]: http://img.shields.io/github/tag/expressjs/api-error-handler.svg?style=flat-square
[github-url]: https://github.com/expressjs/api-error-handler/tags
[travis-image]: https://img.shields.io/travis/expressjs/api-error-handler.svg?style=flat-square
[travis-url]: https://travis-ci.org/expressjs/api-error-handler
[coveralls-image]: https://img.shields.io/coveralls/expressjs/api-error-handler.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/expressjs/api-error-handler
[david-image]: http://img.shields.io/david/expressjs/api-error-handler.svg?style=flat-square
[david-url]: https://david-dm.org/expressjs/api-error-handler
[license-image]: http://img.shields.io/npm/l/api-error-handler.svg?style=flat-square
[license-url]: LICENSE
[downloads-image]: http://img.shields.io/npm/dm/api-error-handler.svg?style=flat-square
[downloads-url]: https://npmjs.org/package/api-error-handler
[gittip-image]: https://img.shields.io/gratipay/jonathanong.svg?style=flat-square
[gittip-url]: https://gratipay.com/expressjs/