Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simple-errors

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-errors

Errors constructor for simple error handling.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

#simple-errors Factory methods for easy error handling.

##Installation

npm install simple-errors

##Usage Just make sure to require the module somewhere in your code (only once)

require('simple-errors');

Then use the factory methods for creating errors:

//simplest of errors
var err = Error.create();

//with message
var err = Error.create('foo');
console.log(err.message === 'foo'); //prints true

//with data
var err = Error.create('foo', { foo: 'bar' });
console.log(err.message === 'foo'); //prints true
console.log(err.foo === 'bar'); //prints true

//with data and inner error
var err = Error.create('foo', { foo: 'bar' }, err);
console.log(err.message === 'foo'); //prints true
console.log(err.foo === 'bar'); //prints true
console.log(err.inner === err); //prints true

//helper for status codes (for use with connect & express)
var err = Error.http(500);
console.log(err.status === 500); //prints true

//helper for status codes, with message, data and error
var err = Error.http(500, 'foo', {foo: 'bar'}, err);
console.log(err.status === 500); //prints true
console.log(err.message === 'foo'); //prints true
console.log(err.foo === 'bar'); //prints true
console.log(err.inner === err); //prints true

//helper method for turning the Error instance into a json object
var err = Error.create();
var obj = Error.toJson(err); //use this to print the entire error with stack.

Keywords

FAQs

Package last updated on 06 Mar 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