1 /**
  2  * @file Exceptions handler
  3  *
  4  * @author Dominik Kocuj
  5  * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 or later
  6  * @copyright Copyright (c) 2016-2018 kocuj.pl
  7  */
  8 
  9 (function() {})(); // empty function for correct minify with comments
 10 //'use strict'; // for jshint uncomment this and comment line above
 11 
 12 /* jshint strict: true */
 13 /* jshint -W034 */
 14 
 15 /* global kocujILV12aHelper */
 16 
 17 /* global kocujILV12aExceptionCode */
 18 
 19 /**
 20  * Exception prototype constructor
 21  *
 22  * @constructs
 23  * @namespace kocujILV12aCException
 24  * @public
 25  * @param {number} [code] Error code
 26  * @param {string} [filename] Filename with error
 27  * @param {string} [param] Parameter for error information
 28  * @return {void}
 29  */
 30 function kocujILV12aCException(code, filename, param) {
 31 	'use strict';
 32 	/* jshint validthis: true */
 33 	// get this object
 34 	var self = this;
 35 	// parse arguments
 36 	code = kocujILV12aHelper.initNumeric(code);
 37 	filename = kocujILV12aHelper.initString(filename);
 38 	if (filename === '') {
 39 		filename = 'unknown';
 40 	}
 41 	param = kocujILV12aHelper.initString(param);
 42 	// set errors
 43 	self._setErrors();
 44 	// prepare message
 45 	var msg = '[' + self._getExceptionName() + '] [file: ' + filename + '] ';
 46 	if (self._errors[code] !== undefined) {
 47 		msg += self._errors[code];
 48 	} else {
 49 		msg += 'Unknown error';
 50 	}
 51 	if (param !== '') {
 52 		msg += ' (' + param + ')';
 53 	}
 54 	// set message
 55 	self.message = msg;
 56 }
 57 
 58 // exception prototype
 59 kocujILV12aCException.prototype = new Error();
 60 kocujILV12aCException.prototype.constructor = kocujILV12aCException;
 61 
 62 // errors
 63 kocujILV12aCException.prototype._errors = [];
 64 
 65 /**
 66  * Get errors list
 67  *
 68  * @public
 69  * @return {Array} List of errors where keys are errors codes and values are errors texts
 70  */
 71 kocujILV12aCException.prototype.getErrors = function() {
 72 	'use strict';
 73 	// exit
 74 	return this._errors;
 75 };
 76 
 77 /**
 78  * Get exception name
 79  *
 80  * @private
 81  * @return {string} Exception name
 82  */
 83 kocujILV12aCException.prototype._getExceptionName = function() {
 84 	'use strict';
 85 	// exit
 86 	return 'kocujilv12a';
 87 };
 88 
 89 /**
 90  * Set errors codes and texts
 91  *
 92  * @private
 93  * @return {void}
 94  */
 95 kocujILV12aCException.prototype._setErrors = function() {
 96 	'use strict';
 97 	// set errors
 98 	var codes = kocujILV12aExceptionCode;
 99 	this._errors[codes.OK] = 'OK';
100 	this._errors[codes.EMPTY_PROJECT_ID] = 'Empty project identifier';
101 	this._errors[codes.PROJECT_DOES_NOT_EXIST] = 'Project does not exist';
102 	this._errors[codes.PROJECT_ALREADY_EXISTS] = 'Project already exists';
103 	this._errors[codes.EMPTY_ELEMENT_PATH] = 'Empty element path';
104 	this._errors[codes.ELEMENT_DOES_NOT_EXIST] = 'Element does not exist';
105 	this._errors[codes.JS_AJAX_EMPTY_URL] = 'Empty URL for AJAX script';
106 	this._errors[codes.JS_AJAX_EMPTY_METHOD] = 'Empty method for AJAX script';
107 	this._errors[codes.JS_AJAX_EMPTY_DATA_TYPE] = 'Empty data type for AJAX script';
108 	this._errors[codes.WINDOW_WRONG_TYPE] = 'Wrong window type';
109 	this._errors[codes.WINDOW_WRONG_ATTRIBUTES] = 'Wrong window attributes';
110 };
111