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

spur-errors

v1.0.8

Published

Common error builder utility for Node.js. Contains common error types, and stack trace tracking to support more detailed error messages.

Downloads

952

Readme

Common error builder utility for Node.js. Contains common error types, and stack trace tracking to support more detailed error messages.

NPM Version NPM Install Size NPM Downloads

About the Spur Framework

The Spur Framework is a collection of commonly used Node.JS libraries used to create common application types with shared libraries.

Visit NPMJS.org for a full list of Spur Framework libraries >>

Usage

Supports active Node versions in the LTS Schedule. (view current versions)

Install from NPM

$ npm install --save spur-errors

Require and use the module

let SpurErrors = require("spur-errors");

SpurErrors.NotFoundError.create("could not find it");

API

The API is designed to be daisy chained with all of the following base commands that are a part of all of the error types.

Base Object Commands

.create(message, nativeError) -> instance

Creates an instance of a SpurError for the type used.

try {
  ...
}
catch(err) {
  SpurErrors.NotFound.create("Some error", err);
}

.setErrorCode(errorCode) -> instance

Sets an error code to later be used by error handlers.

SpurErrors.NotFound.create("Not found").setErrorCode("leaf_error");

.setMessage(message) -> instance

Overrides the error message passed in.

SpurErrors.NotFound.create("Not found").setMessage("Unable to find the restaurant.");

.setStatusCode(statusCode) -> instance

Setting the response status code to be sent back down to the client.

SpurErrors.NotFound.create("Not found").setStatusCode(404);

.setData(data) -> instance

Sets customizable data that can be used down the error stack chain.

SpurErrors.NotFound.create("Not found").setData({headers: req.headers});

Properties

| Property | Description | | :------------ | :---------------------------------------------------------------------------------- | | internalError | The original error object passed in | | message | Either passed in during the create call or during the parsing of the internal error | | stack | Parsed from the originally passed in internal error | | errorCode | Custom error code | | statusCode | Custom status code to be used by the Express.JS response | | data | Custom data object to be used anyone in the flow |

Error Types

| Error Type | Status Code | Message | Error Code | | :---------------------- | :---------- | :------------------------ | :------------------------ | | ValidationError | 400 | Validation Error | validation_error | | UnauthorizedError | 401 | Unauthorized Error | unauthorized_error | | ForbiddenError | 403 | Forbidden Error | forbidden_error | | NotFoundError | 404 | Not Found Error | not_found_error | | MethodNotAllowedError | 405 | Method not allowed | method_not_allowed_error | | RequestTimeoutError | 408 | Request Timeout Error | request_timeout_error | | AlreadyExistsError | 409 | Already Exists Error | already_exists_error | | InternalServerError | 500 | Internal Server Error | internal_server_error | | BadGatewayError | 502 | Bad Gateway Error | bad_gateway_error | | ServiceUnavailableError | 503 | Service Unavailable Error | service_unavailable_error | | GatewayTimeoutError | 504 | Gateway Unavailable Error | gateway_timeout_error |

Error type example

SpurErrors.ValidationError.create("Invalid input");
// => {statusCode: 400, message: "Validation Error", errorCode: "validation_error", ....}

Maintainers

This library is maintained by

Collaborators

Contributing

We accept pull requests

Please send in pull requests and they will be reviewed in a timely manner. Please review this generic guide to submitting a good pull requests. The only things we ask in addition are the following:

  • Please submit small pull requests
  • Provide a good description of the changes
  • Code changes must include tests
  • Be nice to each other in comments. :innocent:

Style guide

The majority of the settings are controlled using an EditorConfig configuration file. To use it please download a plugin for your editor of choice.

All tests should pass

To run the test suite, first install the dependancies, then run npm test

$ npm install
$ npm test

License

MIT