Generates custom Http errors


1.0.13 years ago3 years agoMinified + gzip package size for @financial-times/ip-custom-errors in KB



npm version CircleCI

A module that generates custom HTTP errors


Install via npm:

  npm i -S @financial-times/ip-custom-errors


The module exposes three methods to generate the custom HTTP errors. You can use the one that fits your needs as follows:

Using the custom HttpError constructor to create a custom error message, for example:

const { HTTPError } = require('@financial-times/ip-custom-errors');
try {
  throw new HTTPError(401,'Unauthorized','You are not allowed to access this resource')
} catch (err) {

Using the custom HTTPStatusError method with status code and custom message, for example:

const { HTTPStatusErrors } = require('@financial-times/ip-custom-errors');
try {
  throw HTTPStatusErrors['400']('You are not allowed to access this resource')
} catch (err) {

Using the name of the custom error by name

const { NotFound } = require('@financial-times/ip-custom-errors');
try {
  throw NotFound("The resource you requested can't be found");
} catch (err) {

List of error names to use

BadRequest UnsupportedMediaType NotImplemented
Unauthorized RangeNotSatisfiable BadGateway
PaymentRequired Expectation HttpVersionNotSupported
Forbidden MisdirectedRequest VariantAlsoNegotiates
NotFound UnprocessableEntity InsufficientStorage
MethodNotAllowed Locked LoopDetected
NotAcceptable UnorderedCollection NotExtended
ProxyAuthenticationRequired UpgradeRequired NetworkAuthenticationRequired
RequestTimeout PreconditionRequired ServiceUnavailable
Conflict TooManyRequests GatewayTimeout
Gone UnavailableForLegalReasons BandwidthLimitExceeded
LengthRequired InternalServerError
PreconditionFailed ImATeapot
PayloadTooLarge FailedDependency
UriTooLong RequestHeaderFieldsTooLarge



If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.