esrol-errors
v0.3.6
Published
An Errors Class for esrol-server-app. It is used for registering new custom errors with numbers, can get a single or all errors in the registry, has a custom throw error method.
Downloads
12
Maintainers
Readme
esrol-errors
An Errors Class for esrol-server-app. It is used for registering new custom errors with numbers, can get a single or all errors in the registry, has a custom throw error method.
Part of Esrol
Installation
$ npm install --save esrol-errors
Usage
'use strict';
let Errors = require('esrol-errors');
let errors = new Errors();
errors.registerErrorWithNumber('Some error message', 1);
let all = errors.getAllErrors();
let error = errors.getByNumber(1);
console.log (error); // Some error message
console.log (all); // { '1': 'Some error message' }
try {
errors.error('the reason for this erros is to show some example', 1);
} catch(e) {
console.log (e);
}
Methods
Returns: boolean - true - returns true if adding was successful Throws:
- error error - when incorrect arguments have been passed
| Param | Type | Description | | --- | --- | --- | | description | string | description text of the error | | number | int | the number that the error will have |
getByNumber(number) ⇒ object
Get an error by it's number.
Returns: string - - returns the message of the error
| Param | Type | Description | | --- | --- | --- | | number | int | the number of the error |
getAllErrors() ⇒ object
Get the whole registry with all the errors. This method returns the output of getAll from the Register class.
Returns: object - - returns all the errors in the registry
error(message, code) ⇒ error
Custom method for error handling.
| Param | Type | Description | | --- | --- | --- | | message | string | message / text of the error | | code | int | the number that the error has |
Contriubtion
Any contribution will be highly appreciated. Just make sure that:
1.Your code works.
2. You have 100% successful tests coverage.
3. You have comments in your code.
4. Follows eslint config. Exceptions are possible where that make sense.
Tests
To run the test suite, first install the dependencies, then run npm test
:
$ npm install
$ npm test