1.0.1 • Published 8 years ago

errors-node v1.0.1

Weekly downloads
25
License
MIT
Repository
github
Last release
8 years ago

Common Errors for Node.js

Common errors for your Node.js app. These errors are designed to be used in any layer of the app.

Usage

Simply reference this module in the dependencies key of your package.json file...

"errors": "git@github.com:cybric/errors-node.git"

...and go to town...

const errors = require('errors');
const dataz = require('dataz');

const getMehDataz = (id) => {
  dataz.get(id)
  .then((item) => {
    if (item) return item;
    throw new errors.NotFoundError();
  });
}

API

TLDR: you use the errors in this library like you would any JavaScript error.

FormatError

Represents a request with an invalid format.

Properties

  • message: a description of the error.
  • data: if provided at construction time, an object containing additional information about the error.
  • defaultMessage: (static) the default message used if one is not supplied to the constructor.

Methods

  • constructor
    • Parameters
      • message: (optional) the string value to use for the message.
      • data: (optional) additional data to include with the error.

ValidationError

Thrown when an argument is properly formed, but contains invalid information.

Properties

  • message: a description of the error.
  • data: if provided at construction time, an object containing additional information about the error.
  • defaultMessage: (static) the default message used if one is not supplied to the constructor.

Methods

  • constructor
    • Parameters
      • message: (optional) the string value to use for the message.
      • data: (optional) additional data to include with the error.

CredentialsError

Thrown when authentication credentials or an identity token is invalid.

Properties

  • message: a description of the error.
  • data: if provided at construction time, an object containing additional information about the error.
  • defaultMessage: (static) the default message used if one is not supplied to the constructor.

Methods

  • constructor
    • Parameters
      • message: (optional) the string value to use for the message.
      • data: (optional) additional data to include with the error.

UnauthorizedError

Thrown when an authenticated user does not have sufficient permissions to perform an operation.

Properties

  • message: a description of the error.
  • data: if provided at construction time, an object containing additional information about the error.
  • defaultMessage: (static) the default message used if one is not supplied to the constructor.

Methods

  • constructor
    • Parameters
      • message: (optional) the string value to use for the message.
      • data: (optional) additional data to include with the error.

NotFoundError

Thrown when a requested resource does not exist.

Properties

  • message: a description of the error.
  • data: if provided at construction time, an object containing additional information about the error.
  • defaultMessage: (static) the default message used if one is not supplied to the constructor.

Methods

  • constructor
    • Parameters
      • message: (optional) the string value to use for the message.
      • data: (optional) additional data to include with the error.

ConcurrencyError

Thrown when a provided resource version value (etag) does not match the current version value.

Properties

  • message: a description of the error.
  • data: if provided at construction time, an object containing additional information about the error.
  • defaultMessage: (static) the default message used if one is not supplied to the constructor.

Methods

  • constructor
    • Parameters
      • message: (optional) the string value to use for the message.
      • data: (optional) additional data to include with the error.

TempUnavailableError

Thrown when a service is temporarily unavailable. If this error is encountered, a retry should be attempted.

Properties

  • message: a description of the error.
  • data: if provided at construction time, an object containing additional information about the error.
  • defaultMessage: (static) the default message used if one is not supplied to the constructor.

Methods

  • constructor
    • Parameters
      • message: (optional) the string value to use for the message.
      • data: (optional) additional data to include with the error.