"use strict";
/**
 * Error hierarchy used throughout the library.
 *
 * - {@link BaseError}      — root class; all custom errors extend it.
 * - {@link FatalError}     — code `EFATAL`; non-recoverable problem (network, programmer mistake, etc.).
 * - {@link ParseError}     — code `EPARSE`; the response from Telegram could not be parsed.
 * - {@link TelegramError}  — code `ETELEGRAM`; the Bot API returned `ok: false`.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.errors = exports.TelegramError = exports.ParseError = exports.FatalError = exports.BaseError = void 0;
class BaseError extends Error {
    code;
    constructor(code, message) {
        super(`${code}: ${message}`);
        this.code = code;
        this.name = new.target.name;
        // Restore prototype chain when targeting older TS module emit
        Object.setPrototypeOf(this, new.target.prototype);
    }
    toJSON() {
        return { code: this.code, message: this.message };
    }
}
exports.BaseError = BaseError;
class FatalError extends BaseError {
    cause;
    constructor(data) {
        const message = typeof data === "string" ? data : data.message;
        super("EFATAL", message);
        if (typeof data !== "string") {
            this.stack = data.stack;
            this.cause = data;
        }
    }
}
exports.FatalError = FatalError;
class ParseError extends BaseError {
    response;
    constructor(message, response) {
        super("EPARSE", message);
        this.response = response;
    }
}
exports.ParseError = ParseError;
class TelegramError extends BaseError {
    response;
    constructor(message, response) {
        super("ETELEGRAM", message);
        this.response = response;
    }
}
exports.TelegramError = TelegramError;
exports.errors = { BaseError, FatalError, ParseError, TelegramError };
//# sourceMappingURL=errors.cjs.map