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 🙏

© 2024 – Pkg Stats / Ryan Hefner

eror

v1.0.0

Published

Error utilities which provide error classes for HTTP response (4xx, 5xx) and more.

Downloads

2

Readme

eror

NPM version Build status Coveralls status Support us

Error utilities which provide error classes for HTTP response (4xx, 5xx) and more.

Installation

$ npm install eror

Example

// Formatted message
new eror.InvalidTypeError('"%s" must be a string!', 'name');

// Custom status code
new eror.MissingValueError(400, '"%s" is required!', 'age');

// Pre-defined HTTP errors
new eror.NotFoundError('User "%s" not found!', 'paul');

// Custom errors
eror(503, 'The Earth is %s!', 'exploding');

API reference

eror([statusCode], [message || format], [...values])

Create a custom error.

eror(401, 'You are not logged in!');
eror('Welcome, %s %s.', 'John', 'Lennon');
  • statusCode: Status code as a number, defaults to 500.
  • message: Error message.
  • format: Placeholder string, please refer to util.format for more details.
  • ...values: Values to be placed in placeholder string.

new eror[name]([statusCode], [message || format], [...values])

Instantiate a new common error.

new eror.MissingValueError(400, '"%s" field is required!', 'name');
  • name: Class name of the error, as specified in common error list.
  • statusCode: Status code, if is not specified, default status code, 500, will be used.
  • message, format and ...values: as in eror().

new eror[name || statusCode]([message || format], [...values])

Instantiate a new HTTP error.

new eror.NotFoundError('Requested resource not found!');
new eror[500]('Server exploded at %s!', new Date());
  • name: Class name of the error, as specified in HTTP error list.
  • statusCode: Status code of HTTP error.
  • message, format and ...values: as in eror().

HTTP error's status code cannot be overridden.

Error properties

var err = eror(404, 'Nothing!');

err.message; // Nothing!
err.statusCode; // 404
err.status; // also 404
  • message
  • statusCode and status: Status code of the error.

Error class properties

eror.InternalServerError.MESSAGE; // Internal Server Error
eror.InternalServerError.STATUS_CODE; // 500
eror.InternalServerError.STATUS; // also 500
  • MESSAGE: Default error message of errors which are instantiate from this class.
  • STATUS_CODE and STATUS: Default status code.

Error list

Common errors

| Class name | Status code | | ------------------------- |:-----------:| | UnsupportedOperationError | 500 | | ReversedNameError | 500 | | NameAlreadyDefinedError | 500 | | InvalidOperationError | 500 | | InvalidTypeError | 500 | | MissingValueError | 500 | | InvalidValueError | 500 |

HTTP errors

| Class name | Status code | | ---------------------------------- |:-----------:| | BadRequestError | 400 | | UnauthorizedError | 401 | | PaymentRequiredError | 402 | | ForbiddenError | 403 | | NotFoundError | 404 | | MethodNotAllowedError | 405 | | NotAcceptableError | 406 | | ProxyAuthenticationRequiredError | 407 | | RequestTimeoutError | 408 | | ConflictError | 409 | | GoneError | 410 | | LengthRequiredError | 411 | | PreconditionFailedError | 412 | | PayloadTooLargeError | 413 | | UriTooLongError | 414 | | UnsupportedMediaTypeError | 415 | | RangeNotSatisfiableError | 416 | | ExpectationFailedError | 417 | | ImATeapotError | 418 | | UnprocessableEntityError | 422 | | LockedError | 423 | | FailedDependencyError | 424 | | UnorderedCollectionError | 425 | | UpgradeRequiredError | 426 | | PreconditionRequiredError | 428 | | TooManyRequestsError | 429 | | RequestHeaderFieldsTooLargeError | 431 | | UnableForLegalReasonsError | 451 | | InternalServerError | 500 | | NotImplementedError | 501 | | BadGatewayError | 502 | | ServiceUnavailableError | 503 | | GatewayTimeoutError | 504 | | HttpVersionNotSupportedError | 505 | | VariantAlsoNegotiatesError | 506 | | InsufficientStorageError | 507 | | LoopDetectedError | 508 | | BandwidthLimitExceededError | 509 | | NotExtendedError | 510 | | NetworkAuthenticationRequiredError | 511 |

Contributing

  • Submit new issue if there is any common error, which is useful for you or others, unavailable.

  • In lieu of a formal styleguide, take care to maintain the existing coding style. .editorconfig and .jshintrc files can give you more details.

  • Add tests for any new or changed functionality/element.

  • Lint and test your code using npm test.

Author

License

Released under MIT license.