JSPM

@carnesen/coded-error

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1554
  • Score
    100M100P100Q106391F
  • License MIT

An enhanced JavaScript `Error` class with additional properties "code" and "data"

Package Exports

  • @carnesen/coded-error

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 (@carnesen/coded-error) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

coded-error Build Status

An enhanced Error class with additional properties "code" and "data"

Install

$ npm install @carnesen/coded-error

This package includes runtime JavaScript files suitable for Node.js >=8 or a modern non-IE browser as well as the corresponding TypeScript type declarations.

Usage

import { CodedError } from '@carnesen/coded-error';

const err = new CodedError('An error has occurred', 127, { foo: 'bar' });

console.log(err);
/*
{ Error: An error has occurred
    at Object.<anonymous> (/Users/carnesen/GitHub/coded-error/example.js:3:13)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)
    at bootstrap_node.js:625:3
 code: 127, data: { foo: 'bar' } }
*/

API

new CodedError(message, code, data)

message

Type: string (optional)

An error message passed into the native Error constructor

code

Type: any

An error code attached to the resulting error object

data

Type: any

An arbitrary payload attached to the error object as the "data" property

More information

If you encounter any bugs or have any questions or feature requests, please don't hesitate to file an issue or submit a pull request on this project's repository on GitHub.

License

MIT © Chris Arnesen