JSPM

deferror

0.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q29244F
  • License MIT

Define hierarchical custom error constructors with ease

Package Exports

  • deferror

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (deferror) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

deferror

Define hierarchical-structured error constructors, the easy way.

Install

$ npm install --save deferror

Usage

var deferror = require('deferror')

var errors = deferror([
  {
    name: 'TransactionError',
    code: 'TRANSACTION',
    errors: [
      {
        name: 'InvalidAmountError',
        code: 'INVALID_AMOUNT',
        message: 'The transaction could not be completed with the amount {0} USD specified. The amount exceeds your balance of {1} USD.'
      },
      {
        name: 'NotFoundError',
        code: 'NOT_FOUND',
        message: 'The transaction with the ID: {0} could not be found.'
      }
    ]
  }
])

var transactionInvalidAmountError = new errors.TransactionError.InvalidAmountError(120, 100)

assert(transactionInvalidAmountError instanceof Error)

assert(transactionInvalidAmountError instanceof errors.TransactionError.InvalidAmountError)

assert.equal(transactionInvalidAmountError.message, 'The transaction could not be completed with the amount 120 USD specified. The amount exceeds your balance of 100 USD.')

assert.equal(transactionInvalidAmountError.code, 'TRANSACTION::INVALID_AMOUNT')

Test

$ npm test

License

MIT © 2016 Saran Siriphantnon <deoxen0n2@gmail.com>