-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,51 @@ | ||
# express-json-error-handler | ||
# express-json-error-handler [![Build Status](https://travis-ci.org/noamokman/express-json-error-handler.svg?branch=master)](https://travis-ci.org/noamokman/express-json-error-handler) [![Coverage Status](https://coveralls.io/repos/github/noamokman/express-json-error-handler/badge.svg?branch=master)](https://coveralls.io/github/noamokman/express-json-error-handler?branch=master) | ||
|
||
Error handler for express JSON APIs | ||
|
||
|
||
## Installation | ||
``` bash | ||
$ [sudo] npm install express-json-error-handler --save | ||
``` | ||
|
||
## Usage | ||
|
||
### Example | ||
``` js | ||
import express from 'express'; | ||
import jsonErrorHandler from 'express-json-error-handler'; | ||
|
||
const app = express(); | ||
|
||
app.use(jsonErrorHandler()); | ||
|
||
``` | ||
|
||
## Options | ||
|
||
The `jsonErrorHandler` 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 server errors occur. | ||
#### Example | ||
``` js | ||
import express from 'express'; | ||
import jsonErrorHandler from 'express-json-error-handler'; | ||
|
||
const app = express(); | ||
|
||
app.use(jsonErrorHandler({ | ||
log({err, req, res}) { | ||
console.log(err); // The original error object | ||
console.log(req); // The request object | ||
console.log(res); // The response object | ||
} | ||
})); | ||
|
||
``` | ||
|
||
## License | ||
|
||
[MIT](LICENSE) |