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 
An enhanced JavaScript Error
class with additional properties "code" and "data"
Install
$ npm install @carnesen/coded-error
TypeScript usage
This package is written in TypeScript and already contains suitable types for all features.
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' } }
*/
JavaScript usage
const { CodedError } = require('@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
Related
- @carnesen/run-and-exit: Run an async function, console.log the result, then exit
License
MIT © Chris Arnesen