1.0.2 • Published 5 years ago

@xtrctio/xerror v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

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)

ParamTypeDefaultDescription
messagestringerror message
codenumber500http error code
dataanyany extra data to attach to the error
1.0.2

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago