@xtrctio/xerror
v1.0.2
Published
xtrct.io error class
Downloads
4
Readme
xerror
xtrct.io error class
Install
npm i -S @xtrctio/xerror
Use
const XError = require('@xtrctio/xerror');
// Throws error which inheirits from Error and has a default http code of 500 INTERNAL_SERVER_ERROR
const throws = () => { throw new XError('boom'); };
// Throw with a different http code
// XError.HTTP_STATUS is just the 'http-status' package
const throwsWithHttpError = () => { throw new XError('boom', XError.HTTP_STATUS.BAD_REQUEST); };
// Throw with special data
const throwsWithData = () => { throw new XError('boom', undefined, {foo: 'bar'}); };
XError
Kind: global class
new XError(message, [code], [data])
| Param | Type | Default | Description | | --- | --- | --- | --- | | message | string | | error message | | [code] | number | 500 | http error code | | [data] | any | | any extra data to attach to the error |