|
|
11 месяцев назад | |
|---|---|---|
| .. | ||
| HISTORY.md | 11 месяцев назад | |
| LICENSE | 11 месяцев назад | |
| README.md | 11 месяцев назад | |
| index.js | 11 месяцев назад | |
| package.json | 11 месяцев назад | |
Create HTTP errors for Express, Koa, Connect, etc. with ease.
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();
})
This is the current API, currently extracted from Koa and subject to change.
messagestatus and statusCode - the status code of the error, defaulting to 500var 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 objectvar err = new createError.NotFound();
code - the status code as a numbername - the name of the error as a "bumpy case", i.e. NotFound or InternalServerError.