1.0.0 • Published 7 years ago

nw-connect-http-errors v1.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

nw-connect-http-errors

Install

npm install nw-connect-http-errors

Usage

var app = require('connect')();
var createError = require('http-errors');
var httpErrorsHandler = require('nw-connect-http-errors');

app.use(function ExampleHandler(req, res, next) {
    // Raise Error

    next(createError(404, 'Resource not found', {
        details: {
            url: req.url
        }
    }));
});

// ensure this is last middleware
app.use(httpErrorsHandler());

JSON response is:

{
    "error": {
        "name": "NotFound",
        "message": "Resource not found",
        "details": {
            "url": "some url"
        }
    }
}