/**
 * Занимается логированием ошибок и отправкой их в sentry
 */
export class ErrorService {
    constructor(logger) {
        this.logger = logger;
        this.captureException = (error, extra) => {
            if (this._captureException) {
                this._captureException(error, extra ? { extra } : undefined);
            }
        };
        this.captureCustomError = (place, message) => {
            this.captureException(this.createError(place, message));
        };
        /**
         * Логирует ошибку в консоль и отправляет в sentry
         * */
        this.logError = (place, message) => {
            const error = this.createError(place, message);
            this.logger.error(error);
            this.captureException(error);
        };
        this.createError = (componentName, message) => {
            return new Error(`ASTRAL_UI:${componentName}: ${message}`);
        };
    }
    init(captureException) {
        this._captureException = captureException;
    }
    static getInstance() {
        if (!ErrorService.instance) {
            ErrorService.instance = new ErrorService(console);
        }
        return ErrorService.instance;
    }
}
