Express.js error handling middleware to be used for uniformly formatting errors returned from API calls.
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
.travis.yml
README.md
errorHandler.js
package.json

README.md

Build Status Coverage Status npm version

error-handler

Express.js error handling middleware.

Installation

$ npm install cc-error-handler

Running the tests

$ npm install
$ mocha

API

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:

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())