http-error-prototype

1.0.0 • Public • Published

HTTP error prototype

A simple module to deal coherently with HTTP errors in Express. Has conveniency methods for the most commons HTTP error codes. See http-error-express for the companion error handling middleware.

Usage

var express = require('express');
var HttpError = require('http-error-prototype');
 
var router = express.Router();
 
// Shorthand method
router.get('/shorthand', function(req, res, next) {
    return next(HttpError.notFound("Some not found message", { someProp: "someVal" }));
});
 
// Constructor
router.get('/constructor', function(req, res, next) {
    return next(new HttpError(404, "Some not found message", { someProp: "someVal" }));
});
 
module.exports = router;

API

  • new HttpError(status, message, data).
  • HttpError.badRequest(status, message, data).
  • HttpError.unauthorized(status, message, data).
  • HttpError.forbidden(status, message, data).
  • HttpError.notFound(status, message, data).
  • HttpError.methodNotAllowed(status, message, data).
  • HttpError.notAcceptable(status, message, data).
  • HttpError.requestTimeout(status, message, data).
  • HttpError.conflict(status, message, data).

Both message and data are optional.

Readme

Keywords

none

Package Sidebar

Install

npm i http-error-prototype

Weekly Downloads

2

Version

1.0.0

License

LGPL-3.0

Unpacked Size

2.8 kB

Total Files

3

Last publish

Collaborators

  • uwburn