Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error printing #194

Merged
merged 3 commits into from
Feb 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 2 additions & 31 deletions src/error/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {Category} from './category'
import type {CategoryType} from './category'

const CLASS_NAME: string = 'Error';
const UNKNOWN: string = 'UNKNOWN';

/**
* @classdesc This is a description of the error class.
Expand Down Expand Up @@ -44,36 +43,8 @@ export default class Error {
this.category = category;
this.code = code;
this.data = data;
if (getLogLevel(CLASS_NAME) === LogLevel.DEBUG) {
this._createReadableError(category, code, data);
if (getLogLevel(CLASS_NAME) !== LogLevel.OFF) {
Error._logger.error(`Category:${category} | Code:${code} |`, data);
}
}

/**
* creates a readable form of the error
* @param {number} category - error's category.
* @param {number} code - error's code.
* @param {any} data - additional data for the error.
* @returns {void}
*/
_createReadableError(category: number, code: number, data: any = {}): void {
const codeName = this._getKey(Error.Code, code);
const categoryName = this._getKey(Error.Category, category);
Error._logger.error(`Player error ${categoryName}.${codeName}`, data);
}

/**
* returns the string key of the number sent (from the enum)
* @param {Object} obj - reference to the code / category
* @param {number} value - category's / code's number.
* @returns {string} - the key string
*/
_getKey(obj: Object, value: number): string {
for (let strKey in obj) {
if (value === obj[strKey]) {
return strKey;
}
}
return UNKNOWN;
}
}