esrol-errors
Version:
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.
153 lines (126 loc) • 4.33 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: errors.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: errors.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* @author Ivaylo Ivanov
* @public
* @class Errors
* @description 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.
* @requires errors
* @requires register
*/
'use strict';
let errors = require('errors');
let Register = require('./register');
module.exports = class Errors {
/**
* @public
* @method constructor
* @description Initialize Register class
*/
constructor() {
this._Register = new Register();
}
/**
* @public
* @method registerErrorWithNumber
* @description Register / set an error with a number. This method returns
* the output of setErrorWithNumber from the Register class.
* @param {string} description - description text of the error
* @param {int} number - the number that the error will have
* @throws {error} - if thrown by setErrorWithNumber
* @returns {true}
* @see {@link setErrorWithNumber}
*/
registerErrorWithNumber(description, number) {
return this._Register.setErrorWithNumber(description, number);
}
/**
* @public
* @method getByNumber
* @description Get an error by it's number. This method returns
* the output of getByNumber from the Register class.
* @param {int} number - the number of the error
* @returns {object}
* @see {@link getByNumber}
*/
getByNumber(number) {
return this._Register.getByNumber(number);
}
/**
* @public
* @method getAllErrors
* @description Get the whole register with all the errors. This method returns
* the output of getAll from the Register class.
* @returns {object}
* @see {@link getAll}
*/
getAllErrors() {
return this._Register.getAll();
}
/**
* @public
* @method error
* @description custom method for error handling. This method returns
* the output of _throw from this class.
* @param {string} message - message / text of the error
* @param {int} code - the number that the error has
* @returns {error}
* @see {@link _throw}
*/
error(e, code) {
let error = {};
error.name = 'FatalError';
error.defaultMessage = e;
if (typeof code === 'number') {
error.code = code;
error.defaultExplanation = this._Register.getByNumber(code);
}
return this._throw(error);
}
/**
* @private
* @method _throw
* @description custom method for throwing an error
* @param {object} error - the error to be thrown
* @throws {error} CatchAndConsoleLogThisErrorForMoreInfo
* - throws specified error
*/
_throw(error) {
var CatchAndConsoleLogThisErrorForMoreInfo = errors.create(error);
throw new CatchAndConsoleLogThisErrorForMoreInfo();
}
};
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Errors.html">Errors</a></li></ul><h3>Global</h3><ul><li><a href="global.html#constructor">constructor</a></li><li><a href="global.html#error">error</a></li><li><a href="global.html#getAll">getAll</a></li><li><a href="global.html#getAllErrors">getAllErrors</a></li><li><a href="global.html#getByNumber">getByNumber</a></li><li><a href="global.html#registerErrorWithNumber">registerErrorWithNumber</a></li><li><a href="global.html#setErrorWithNumber">setErrorWithNumber</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Thu Nov 26 2015 17:49:03 GMT+0200 (FLE Standard Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>