/**
 * api-client/errors.ts — Typed error classes for API client failures.
 *
 * Each error class corresponds to a distinct failure mode so callers can
 * match on `instanceof` for control flow. Error messages are always
 * human-readable; machine-readable details are in typed fields.
 */
// ---------------------------------------------------------------------------
// ApiError — API returned a non-2xx response with a structured error body
// ---------------------------------------------------------------------------
/**
 * The API returned a well-formed error response (JSON envelope with
 * `object: "error"`). The HTTP status code and error details are preserved.
 */
export class ApiError extends Error {
    code;
    statusCode;
    param;
    name = "ApiError";
    constructor(message, code, statusCode, param) {
        super(message);
        this.code = code;
        this.statusCode = statusCode;
        this.param = param;
    }
}
// ---------------------------------------------------------------------------
// ApiAuthError — 401/403 from the API
// ---------------------------------------------------------------------------
/**
 * The API key is missing, invalid, or lacks the required scope.
 */
export class ApiAuthError extends ApiError {
    name = "ApiAuthError";
}
// ---------------------------------------------------------------------------
// ApiConnectionError — network-level failure
// ---------------------------------------------------------------------------
/**
 * The API could not be reached — DNS failure, connection refused,
 * timeout, or a non-JSON response (e.g., 502 from a CDN).
 */
export class ApiConnectionError extends Error {
    url;
    cause;
    name = "ApiConnectionError";
    constructor(message, url, cause) {
        super(message);
        this.url = url;
        this.cause = cause;
    }
}
// ---------------------------------------------------------------------------
// ApiTimeoutError — polling deadline exceeded
// ---------------------------------------------------------------------------
/**
 * The job did not reach a terminal state within the allotted time.
 */
export class ApiTimeoutError extends Error {
    jobId;
    timeoutMs;
    name = "ApiTimeoutError";
    constructor(jobId, timeoutMs) {
        super(`Job ${jobId} did not complete within ${Math.round(timeoutMs / 1000)}s`);
        this.jobId = jobId;
        this.timeoutMs = timeoutMs;
    }
}
