/**
 * 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`.
 */
export 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 };
    }
}
export 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;
        }
    }
}
export class ParseError extends BaseError {
    response;
    constructor(message, response) {
        super("EPARSE", message);
        this.response = response;
    }
}
export class TelegramError extends BaseError {
    response;
    constructor(message, response) {
        super("ETELEGRAM", message);
        this.response = response;
    }
}
export const errors = { BaseError, FatalError, ParseError, TelegramError };
//# sourceMappingURL=errors.js.map