shoutr
v1.3.3
Published
Error handling
Downloads
10
Readme
shoutr
Install
npm:
npm install shoutr
yarn:
yarn add shoutr
Usage
import { registerErrors, throwError } from 'shoutr';
registerErrors({
wrongParamType: (type) => `You passed param with wrong type: ${type} - expected object`;
someError: 'some string error, without any params';
});
const param = 'some string';
throwError('wrongParamType', TypeError, typeof param);
// should throw an TypeError with message equal 'You passed param with wrong type: string - expected object'
throwError('wrongParamType', typeof param);
// should throw an Error with message equal 'You passed param with wrong type: string - expected object'
throwError('someError');
// should throw an Error with message equal 'some string error, without any params'
throwError('someError', ReferenceError);
// should throw an ReferenceError with message equal 'some string error, without any params'
throwError('error which is not in registered errors');
// should throw an Error with message equal 'error which is not in registered errors'
Contributors
| Name | Website | | --------------- | ------------------- | | Bart Smykla | https://smykla.com |