some-http-error
A javascript error creator for some often used HTTP error
Getting started
Install
$ npm install some-http-error
Usage
You can use this module in any node.js web frameworks, such as express
In controllers
var HttpError = ; { var userId = reqqueryid; // If some error happened if !userId // You can pass it to error handling middleware ; // Or just throw it! // throw new HttpError.BadRequestError('"id" is not set')); // In promise User;}
In error handling middleware
var HttpError = ; { if err instanceof HttpError // If it is an HttpError, send the HTTP status code and error message res; else // Otherwise send 500 res;
API
HttpError(statusCode[, message])
The basic HttpError object constructor, and you can construct HttpError like this:
404404 'This page is not found'
HttpError.BadRequestError([message])
- statusCode:
400
- message:
Bad Request
HttpError.UnauthorizedError([message])
- statusCode:
401
- message:
Unauthorized
HttpError.ForbiddenError([message])
- statusCode:
403
- message:
Forbidden
HttpError.NotFoundError([message])
- statusCode:
404
- message:
Not Found
HttpError.MethodNotAllowedError([message])
- statusCode:
405
- message:
Method Not Allowed