esrol-errors

0.3.6 • Public • Published

NPM version Build Status Test coverage

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

registerErrorWithNumber(description, number)boolean

Register / set an error with a number.

getByNumber(number)object

Get an error by it's number.

getAllErrors()object

Get the whole registry with all the errors.

error(message, code)error

Custom method for error handling.

## registerErrorWithNumber(description, number) ⇒ boolean Add a new error message and corresponding number to the registry.

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

License

MIT

Dependencies (1)

Dev Dependencies (5)

Package Sidebar

Install

npm i esrol-errors

Weekly Downloads

1

Version

0.3.6

License

MIT

Last publish

Collaborators

  • ivaylopivanov