npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

allhttperrors

v0.4.2

Published

A module to create flexible, powerful Error objects based on HTTP responses

Readme

HTTPErrors

This is a simple module to create HTTP error constructor based on Node's http.STATUS_CODES information. How to use it:

var errors = require( 'allhttperrors' );

var e = new errors.UnauthorizedError();
console.log( e.httpError ); // 401

// ...
next( new errors.NotFoundError() );
// ... or:
next( new errors.NotFoundError("The file specified could not be found") );
// ... or:
next( new errors.NotFoundError(
  { message: "The file specified could not be found", extraInfo: { fileName: 'someFile' } }
) );

The error names are based on the default messages set by nodejs, with strange characters stripped out and capitalisation added. See the bottom of this file for the full list of errors constructors created.

By default, each error constructor sets:

  • this.message; if no parameter is passed, it's the name of the error. If a string is passed, then this.message will be assigned to it; if an object is passed, then this.message will be assigned passedObject.message.

  • this.httpError; automatically set depending on the HTTP error

The constructor

By looking at the code above, you probably noticed that the last form of constucting an error shows that the constructor's parameters are very flexible. The constructor can be called in three forms:

  • NotFoundError(). This will create an error of type NotFoundError, where this.message is Not found.
  • NotFoundError( 'Custom message' ). This will create an error of type NotFoundError, where this.message is Custom Message.
  • NotFoundError( { message: "Custom message", filename: 'log.txt' } ). This will create an error of type NotFoundError, where this.message is Custom Message and this.fileName is log.txt. Basically, the passed object will be mixed into the created object.

If you pass an passedObject to the constructor as a parameter, then every attribute of passedObject will be mixed into the object itself. This is really handy if you want to attach extra information to your error objects. If you are using express, your error handler might look into the err variable and use the extra information.

Note: Only the first parameter is standard in the creation of the Error object. In Firefox, it is new Error([message[, fileName[, lineNumber]]]), in IE it is new Error([number[, description]]), in Chrome, new Error(description, constr). I made the constructor as standard as possible: new Error("Message"), the basic use case, works.

The full list

Here is a full list of error constructors defined by the module. NOTE:: I realise that not all of them are errors. However, the main goal of this module is to create errors around HTTP statuses. I could:

  • either rename it into allhttpstatuses (but that wouldn't really highlight the purpose of the module, that is to create errors)
  • or take out the statuses that aren't errors (but that would imply taking out 100, all 200, but also take out 304 which isn't technically an error... do you see the issue here?)

I won't do either of them, as the goal of this module is to create javascript errors around HTTP statuses.

  • [100] ContinueError: Continue
  • [101] SwitchingProtocolsError: Switching Protocols
  • [102] ProcessingError: Processing
  • [200] OKError: OK
  • [201] CreatedError: Created
  • [202] AcceptedError: Accepted
  • [203] NonAuthoritativeInformationError: Non-Authoritative Information
  • [204] NoContentError: No Content
  • [205] ResetContentError: Reset Content
  • [206] PartialContentError: Partial Content
  • [207] MultiStatusError: Multi-Status
  • [300] MultipleChoicesError: Multiple Choices
  • [301] MovedPermanentlyError: Moved Permanently
  • [302] MovedTemporarilyError: Moved Temporarily
  • [303] SeeOtherError: See Other
  • [304] NotModifiedError: Not Modified
  • [305] UseProxyError: Use Proxy
  • [307] TemporaryRedirectError: Temporary Redirect
  • [400] BadRequestError: Bad Request
  • [401] UnauthorizedError: Unauthorized
  • [402] PaymentRequiredError: Payment Required
  • [403] ForbiddenError: Forbidden
  • [404] NotFoundError: Not Found
  • [405] MethodNotAllowedError: Method Not Allowed
  • [406] NotAcceptableError: Not Acceptable
  • [407] ProxyAuthenticationRequiredError: Proxy Authentication Required
  • [408] RequestTimeOutError: Request Time-out
  • [409] ConflictError: Conflict
  • [410] GoneError: Gone
  • [411] LengthRequiredError: Length Required
  • [412] PreconditionFailedError: Precondition Failed
  • [413] RequestEntityTooLargeError: Request Entity Too Large
  • [414] RequestURITooLargeError: Request-URI Too Large
  • [415] UnsupportedMediaTypeError: Unsupported Media Type
  • [416] RequestedRangeNotSatisfiableError: Requested Range Not Satisfiable
  • [417] ExpectationFailedError: Expectation Failed
  • [418] IMATeapotError: I'm a teapot
  • [422] UnprocessableEntityError: Unprocessable Entity
  • [423] LockedError: Locked
  • [424] FailedDependencyError: Failed Dependency
  • [425] UnorderedCollectionError: Unordered Collection
  • [426] UpgradeRequiredError: Upgrade Required
  • [428] PreconditionRequiredError: Precondition Required
  • [429] TooManyRequestsError: Too Many Requests
  • [431] RequestHeaderFieldsTooLargeError: Request Header Fields Too Large
  • [500] InternalServerErrorError: Internal Server Error
  • [501] NotImplementedError: Not Implemented
  • [502] BadGatewayError: Bad Gateway
  • [503] ServiceUnavailableError: Service Unavailable
  • [504] GatewayTimeOutError: Gateway Time-out
  • [505] HTTPVersionNotSupportedError: HTTP Version not supported
  • [506] VariantAlsoNegotiatesError: Variant Also Negotiates
  • [507] InsufficientStorageError: Insufficient Storage
  • [509] BandwidthLimitExceededError: Bandwidth Limit Exceeded
  • [510] NotExtendedError: Not Extended
  • [511] NetworkAuthenticationRequiredError: Network Authentication Required