New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

spur-errors

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spur-errors

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

  • 0.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
137
increased by41.24%
Maintainers
2
Weekly downloads
 
Created
Source
Spur: Errors

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

NPM version Build Status

Usage

Install from NPM

$ npm install --save spur-errors

Require and use the module

var 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
Error type example
SpurErrors.ValidationError.create("Invalid input")
// => {statusCode: 400, message: "Validation Error", errorCode: "validation_error", ....}

Running the unit tests

To run the test suite, first install the dependencies, then run npm test:

$ npm install
$ npm test

Maintainers

This library is maintained by

License

The MIT License (MIT)

Copyright (c) 2015 Spur Framework.

Copyright (c) 2015 OpenTable Inc. and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Package last updated on 31 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc