Package Exports
- http-errors
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (http-errors) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
http-errors
Create HTTP errors for Express, Koa, Connect, etc. with ease.
Example
var createError = require('http-errors');
app.use(function (req, res, next) {
if (!req.user) return next(createError(401, 'Please login to view this page.'));
next();
})
API
This is the current API, currently extracted from Koa and subject to change.
Error Properties
message
status
andstatusCode
- the status code of the error, defaulting to500
createError([status], [message], [properties])
var err = createError(404, 'This video does not exist!');
status: 500
- the status code as a numbermessage
- the message of the error, defaulting to node's text for that status code.properties
- custom properties to attach to the object
new createError[code || name]([msg]))
var err = new createError.NotFound();
code
- the status code as a numbername
- the name of the error as a "bumpy case", i.e.NotFound
orInternalServerError
.