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

error.js

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

error.js

Custom errors in javascript (browser and server support)

  • 1.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
122
decreased by-13.48%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Dependency Status devDependency Status Build Status

Create custom errors in javascript

var MyCustomError = CustomError.create("MyCustomError");

throw new MyCustomError("Ooops");

Installation

$ npm install --save error.js

Quick start

/* Require the dependency */
var CustomError = require("error.js");

/* Create your custom error once */
var MyCustomError = CustomError.create("MyCustomError");

/* Throw your custom error */
throw new MyCustomError("oops");

Usage

Create a custom error :

var MyCustomName = CustomError.create("MyCustomName");

Create a custom error with additional properties :

var NotFoundError = CustomError.create({
	name : "NotFound",
	message : "Content not found",
	statusCode : 404
});

Throw a custom error :

throw new MyCustomError("oops");

Throw a custom error with additional properties :

throw new NotFoundError({
	message : "Could not find requested user",
	userId : "123-456-789"
});

Check if an Error is a custom error :

var MyCustomError = CustomError.create("MyCustomError");
var myCustomError = new MyCustomError("oops");

/* Will return true */
CustomError.isCustom(myCustomError);
var e = new Error("oops");

/* Will return false */
CustomError.isCustom(e);

Keywords

FAQs

Package last updated on 11 Jan 2016

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