1
0
Fork 0
arangodb/js/node/node_modules/http-errors
Alan Plum 501f5a3f51 Removed unused modules. 2015-04-10 00:33:47 +02:00
..
node_modules Removed unused modules. 2015-04-10 00:33:47 +02:00
HISTORY.md Updated deps. 2015-03-24 21:51:05 +01:00
LICENSE Added http-errors, media-typer, qs as deps. 2015-01-20 17:16:32 +01:00
README.md Added http-errors, media-typer, qs as deps. 2015-01-20 17:16:32 +01:00
index.js Updated deps. 2015-03-24 21:51:05 +01:00
package.json Updated deps. 2015-03-24 21:51:05 +01:00

README.md

http-errors

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

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 and statusCode - the status code of the error, defaulting to 500

createError([status], [message], [properties])

var err = createError(404, 'This video does not exist!');
  • status: 500 - the status code as a number
  • message - 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 number
  • name - the name of the error as a "bumpy case", i.e. NotFound or InternalServerError.

License

MIT