README
rerror
roleup.io error class
Install
npm i -S @roleup/xerror
Use
const RError = require('@roleup/rerror');
// Throws error which inheirits from Error and has a default http code of 500 INTERNAL_SERVER_ERROR
const throws = () => { throw new RError('boom'); };
// Throw with a different http code
// XError.HTTP_STATUS is just the 'http-status' package
const throwsWithHttpError = () => { throw new RError('boom', RError.HTTP_STATUS.BAD_REQUEST); };
// Throw with special data
const throwsWithData = () => { throw new RError('boom', undefined, {foo: 'bar'}); };
RError
new RError(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 |