0.2.1 • Published 8 years ago

stderror v0.2.1

Weekly downloads
9
License
ISC
Repository
github
Last release
8 years ago

stderror

Extendable error class derived from native Error object.

Installation

$ npm install stderror

Usage

var StandardError = require("stderror");

throw new StandardError();
throw new StandardError("My custom error.");
throw new StandardError({code: 1000, message: "My custom error."});

//-- also works without using new
throw StandardError("My custom error.");

Methods

extend(name)

extend(options)

Returns the derived error object based on the given argument.

var UnknownError = StandardError.extend("UnknownError");
var SystemError = StandardError.extend({
  code: 2000,
  name: "SystemError",
  message: "System error."
});

var RecordNotFound = StandardError.extend("RecordNotFound");
var UserNotFound = RecordNotFound.extend({
  name: "UserNotFound",
  message: "User not found."
});

define(name)

define(options)

A form of namespacing errors by encapsulating them in a parent error object.

var Exception = StandardError.extend("Exception");
Exception.define("InvalidArgument");
Exception.define({
  code: 1000,
  name: "InvalidPassword",
  message: "Invalid password.",
  parent: "InvalidArgument"
});

throw new Exception.InvalidArgument();
throw new Exception.InvalidPassword();
0.2.1

8 years ago

0.2.0

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago