Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/colored-coins/error-handler
Express.js error handling middleware to be used for uniformly formatting errors returned from API calls.
https://github.com/colored-coins/error-handler
Last synced: 6 days ago
JSON representation
Express.js error handling middleware to be used for uniformly formatting errors returned from API calls.
- Host: GitHub
- URL: https://github.com/colored-coins/error-handler
- Owner: Colored-Coins
- Created: 2016-07-10T16:01:51.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-08-01T13:36:37.000Z (over 8 years ago)
- Last Synced: 2024-12-07T11:09:40.368Z (2 months ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/Colored-Coins/error-handler.svg?branch=master)](https://travis-ci.org/Colored-Coins/error-handler)
[![Coverage Status](https://coveralls.io/repos/github/Colored-Coins/error-handler/badge.svg?branch=master)](https://coveralls.io/github/Colored-Coins/error-handler?branch=master)
[![npm version](https://badge.fury.io/js/cc-error-handler.svg)](https://badge.fury.io/js/cc-error-handler)
# error-handler
Express.js error handling middleware.
## Installation
```sh
$ npm install cc-error-handler
```
## Running the tests
```
$ npm install
$ mocha
```
## API
```javascript
var errorhandler = require('cc-error-handler')
```
### errorhandler(options)
Create new error handling middleware.
#### options
##### env
'development' will include stack trace, and will accumulate original errors
initiated from third party or separate servers. Default is undefined.
##### log
One of two types:
boolean - a boolean for determining whether the error handler should log the error messages. `true` will use `console.error` by default for logging.
function - a function to process an error, invoked with `err`.
Default is `true`.## Example
As with any express error handling middleware, it should be put after the router middleware:
```javascript
var express = require('express')
var app = express()
var bodyParser = require('body-parser')
var errorHandler = require('cc-error-handler')app.use(bodyParser())
app.get('/error', function (req, res, next) {
next('Something went wrong')
})
app.use(errorHandler())
```