0.3.6 • Published 9 years ago

esrol-errors v0.3.6

Weekly downloads
4
License
MIT
Repository
github
Last release
9 years ago

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

Returns: boolean - true - returns true if adding was successful Throws:

  • error error - when incorrect arguments have been passed
ParamTypeDescription
descriptionstringdescription text of the error
numberintthe number that the error will have

getByNumber(number) ⇒ object

Get an error by it's number.

Returns: string - - returns the message of the error

ParamTypeDescription
numberintthe 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.

ParamTypeDescription
messagestringmessage / text of the error
codeintthe 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