1.4.0 • Published 8 years ago

http-status-errors v1.4.0

Weekly downloads
222
License
ISC
Repository
github
Last release
8 years ago

HTTP Status Errors

Throw HTTP error status codes as Errors!

Installation

$ npm install --save http-status-errors

Usage

Import the errors you want to use, or all of them.

import {NotFoundError} from 'http-status-errors';
// or...
import * as errors from 'http-status-errors';

Or if you're stuck with old-fashioned JS:

var NotFoundError = require('http-status-errors').NotFoundError;
// or...
var errors = require('http-status-errors')

Once you've imported the package, just throw as normal. All constructors accept a message as the only argument, otherwise they'll use the default message for that error. All errors also have a code field which is the corresponding HTTP status code as an integer.

E.g.:

throw new NotFoundError('widget not found');

Errors

Below is the list of error names, status codes and default messages that this package supports.

CodeClass nameDefault message
400BadRequestErrorThere is a problem with the submitted request.
401NotAuthenticatedErrorYou are not authenticated. Please authenticate and try again.
402PaymentRequiredErrorThe action you are trying to perform requires payment.
403ForbiddenErrorYou are forbidden from accessing the requested resource.
404NotFoundErrorThe requested resource was not found.
405MethodNotAllowedErrorThe resource does not support the requested method.
406NotAcceptableErrorThe resource cannot be formatted according to the requested type in the Accept header.
409ConflictErrorThere is a conflict with the requested resource.
418TeapotErrorI'm a teapot...
451UnavailableErrorThe requested resource is unavailable for legal reasons.
500InternalServerErrorThe server has encountered an error.
501NotImplementedErrorThe action you are trying to perform is not implemented.
503ServiceUnavailableErrorThe service is currently unavailable.