/**
 * An error that occurred during an HTTP request
 */
export class HTTPError extends Error {
    message;
    type;
    title;
    status;
    url;
    __raw;
    name = 'HTTPError';
    client = 'OpenMeter';
    constructor(message, type, title, status, url, __raw) {
        super(message);
        this.message = message;
        this.type = type;
        this.title = title;
        this.status = status;
        this.url = url;
        this.__raw = __raw;
    }
    static fromResponse(resp) {
        if (resp.response.headers.get('Content-Type') ===
            'application/problem+json' &&
            resp.error) {
            return new HTTPError(`Request failed (${resp.response.url}) [${resp.response.status}]: ${resp.error.detail}`, resp.error.type, resp.error.title, resp.error.status ?? resp.response.status, resp.response.url, resp.error);
        }
        return new HTTPError(`Request failed (${resp.response.url}) [${resp.response.status}]: ${resp.response.statusText}`, resp.response.statusText, resp.response.statusText, resp.response.status, resp.response.url);
    }
    getField(key) {
        return this.__raw?.[key];
    }
}
/**
 * Check if an error is an HTTPError
 * @param error - The error to check
 * @returns Whether the error is an HTTPError
 */
export function isHTTPError(error) {
    return error instanceof HTTPError;
}
//# sourceMappingURL=common.js.map