error.js
1.2.1 • Public • Published

Create custom errors in javascript
var MyCustomError = CustomError.create("MyCustomError");
throw new MyCustomError("Ooops");
Installation
$ npm install --save error.js
Quick start
var CustomError = require("error.js");
var MyCustomError = CustomError.create("MyCustomError");
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");
CustomError.isCustom(myCustomError);
var e = new Error("oops");
CustomError.isCustom(e);
Package Sidebar
Install
Weekly Downloads