1.0.8 • Published 1 month ago

spur-errors v1.0.8

Weekly downloads
16
License
MIT
Repository
github
Last release
1 month ago

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

PropertyDescription
internalErrorThe original error object passed in
messageEither passed in during the create call or during the parsing of the internal error
stackParsed from the originally passed in internal error
errorCodeCustom error code
statusCodeCustom status code to be used by the Express.JS response
dataCustom data object to be used anyone in the flow

Error Types

Error TypeStatus CodeMessageError Code
ValidationError400Validation Errorvalidation_error
UnauthorizedError401Unauthorized Errorunauthorized_error
ForbiddenError403Forbidden Errorforbidden_error
NotFoundError404Not Found Errornot_found_error
MethodNotAllowedError405Method not allowedmethod_not_allowed_error
RequestTimeoutError408Request Timeout Errorrequest_timeout_error
AlreadyExistsError409Already Exists Erroralready_exists_error
InternalServerError500Internal Server Errorinternal_server_error
BadGatewayError502Bad Gateway Errorbad_gateway_error
ServiceUnavailableError503Service Unavailable Errorservice_unavailable_error
GatewayTimeoutError504Gateway Unavailable Errorgateway_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

1.0.8

1 month ago

1.0.7

2 months ago

1.0.6

8 months ago

1.0.5

11 months ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

2 years ago

1.0.1

6 years ago

1.0.0

7 years ago

1.0.0-rc.1

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.2.0-rc.2

8 years ago

0.2.0-rc.1

8 years ago

0.1.0

8 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago