import HTTPResponse from "./HTTPResponse";
export default class HTTPErrorResponse extends HTTPResponse {
    get message() {
        if (!this.data) {
            return "";
        }
        /*
         * Body shapes we accept, in priority order. Each field may be a
         * plain string OR an object — some gateways/proxies return
         * `{ error: { message } }` — so every candidate is coerced to a
         * string. Returning a raw object here is what rendered as
         * "[object Object]" in error banners downstream.
         */
        for (const key of ["data", "message", "error"]) {
            const coerced = HTTPErrorResponse.coerceToMessage(this.data[key]);
            if (coerced) {
                return coerced;
            }
        }
        return "";
    }
    static coerceToMessage(value) {
        var _a;
        if (value === undefined || value === null) {
            return "";
        }
        if (typeof value === "string") {
            return value;
        }
        if (typeof value === "object") {
            // Common nested shapes: { message: "..." } or { error: "..." }.
            const nested = (_a = value["message"]) !== null && _a !== void 0 ? _a : value["error"];
            if (typeof nested === "string" && nested) {
                return nested;
            }
            try {
                return JSON.stringify(value);
            }
            catch (_b) {
                return "Unknown error";
            }
        }
        return String(value);
    }
}
//# sourceMappingURL=HTTPErrorResponse.js.map