/**
 * Error hierarchy for the Amigo Platform SDK.
 * All errors extend AmigoError which can be caught with a single catch.
 */
import type { components } from '../generated/api.js';
export interface ErrorContext {
    statusCode?: number;
    errorCode?: string;
    requestId?: string;
    detail?: string;
    context?: Record<string, unknown>;
    /** Parsed error body (typed when recognized) */
    errorBody?: PlatformErrorBody;
    /** Raw body string for diagnostic logging — populated even on parse failure */
    rawBody?: string;
}
/**
 * FastAPI 422 validation-error body.
 * Surfaces from openapi-typescript so consumers can read field-level errors.
 */
export type HttpValidationErrorBody = components['schemas']['HTTPValidationError'];
/**
 * Default FastAPI HTTPException shape (`raise HTTPException(status_code, detail=...)`).
 *
 * Most platform-api routes that don't define an explicit error model return
 * this shape. `detail` may be a free-form string or a JSON-serializable object.
 */
export interface HttpExceptionBody {
    detail: string | Record<string, unknown> | unknown[];
    /** Populated by request-id middleware on bounded routes */
    request_id?: string;
    /** Populated by typed error responses (e.g. Surface lifecycle errors) */
    error_code?: string;
}
/**
 * Fallback shape used when the response body fails to parse or is empty.
 * `rawBody` is the verbatim text (truncated to 8 KB to avoid log bloat).
 */
export interface UnparseableErrorBody {
    detail: string;
    raw_body: string;
}
/**
 * Discriminated union of all error body shapes the platform API emits.
 *
 * Consumers should use the type guards (`isHttpException`,
 * `isHttpValidationError`, `isUnparseableErrorBody`) rather than checking
 * fields directly — both `HttpExceptionBody` and `HttpValidationErrorBody`
 * have a `detail` field but it is shaped differently.
 */
export type PlatformErrorBody = HttpExceptionBody | HttpValidationErrorBody | UnparseableErrorBody;
/** Base class for all Amigo Platform SDK errors */
export declare class AmigoError<TBody extends PlatformErrorBody = PlatformErrorBody> extends Error {
    readonly statusCode?: number;
    readonly errorCode?: string;
    readonly requestId?: string;
    readonly detail?: string;
    readonly context?: Record<string, unknown>;
    /**
     * Typed body of the error response, when one was returned and successfully
     * parsed. Use the `isHttpException` / `isHttpValidationError` /
     * `isUnparseableErrorBody` type guards to narrow the discriminated union.
     *
     * Named `errorBody` (not `body`) to avoid colliding with the legacy
     * `ParseError.body: string` field.
     */
    readonly errorBody?: TBody;
    /**
     * Raw response body (truncated to 8 KB). Populated even when parsing fails,
     * so callers always have something to log when debugging server errors.
     */
    readonly rawBody?: string;
    constructor(message: string, ctx?: ErrorContext);
    toJSON(): Record<string, unknown>;
}
/** 400 Bad Request */
export declare class BadRequestError extends AmigoError {
    constructor(message: string, ctx?: ErrorContext);
}
/** 401 Unauthorized — invalid or missing API key */
export declare class AuthenticationError extends AmigoError {
    constructor(message: string, ctx?: ErrorContext);
}
/** 403 Forbidden — insufficient permissions */
export declare class PermissionError extends AmigoError {
    constructor(message: string, ctx?: ErrorContext);
}
/** 404 Not Found */
export declare class NotFoundError extends AmigoError {
    constructor(message: string, ctx?: ErrorContext);
}
/** 409 Conflict — duplicate slug or resource version conflict */
export declare class ConflictError extends AmigoError {
    constructor(message: string, ctx?: ErrorContext);
}
/** 422 Unprocessable Entity — validation failure */
export declare class ValidationError extends AmigoError {
    constructor(message: string, ctx?: ErrorContext);
}
/** 429 Too Many Requests */
export declare class RateLimitError extends AmigoError {
    readonly retryAfter?: number;
    constructor(message: string, ctx?: ErrorContext & {
        retryAfter?: number;
    });
}
/** 5xx Server Error */
export declare class ServerError extends AmigoError {
    constructor(message: string, ctx?: ErrorContext);
}
/** 503 Service Unavailable */
export declare class ServiceUnavailableError extends ServerError {
    constructor(message: string, ctx?: ErrorContext);
}
/** Network or fetch failure (no HTTP status available) */
export declare class NetworkError extends AmigoError {
    constructor(message: string, cause?: unknown);
}
/** Request timed out before receiving a response */
export declare class RequestTimeoutError extends NetworkError {
    readonly timeoutMs?: number;
    constructor(message: string, timeoutMs?: number, cause?: unknown);
}
/** Failed to parse response body */
export declare class ParseError extends AmigoError {
    readonly body?: string;
    constructor(message: string, body?: string);
}
/** SDK misconfiguration */
export declare class ConfigurationError extends AmigoError {
    constructor(message: string);
}
export declare function createApiError(response: Response): Promise<AmigoError>;
export declare function isAmigoError(err: unknown): err is AmigoError;
export declare function isNotFoundError(err: unknown): err is NotFoundError;
export declare function isRateLimitError(err: unknown): err is RateLimitError;
export declare function isAuthenticationError(err: unknown): err is AuthenticationError;
export declare function isRequestTimeoutError(err: unknown): err is RequestTimeoutError;
export declare function isPermissionError(err: unknown): err is PermissionError;
export declare function isConflictError(err: unknown): err is ConflictError;
export declare function isValidationError(err: unknown): err is ValidationError;
export declare function isServerError(err: unknown): err is ServerError;
export declare function isNetworkError(err: unknown): err is NetworkError;
/**
 * Narrowed AmigoError where `errorBody` is guaranteed non-undefined.
 * Used as the return-type for body type guards so consumers don't need to
 * re-assert `errorBody !== undefined` after the guard.
 */
export type AmigoErrorWithBody<TBody extends PlatformErrorBody> = AmigoError<TBody> & {
    readonly errorBody: TBody;
};
/**
 * True when `err.errorBody` is the FastAPI 422 validation-error shape (an
 * object with `detail: ValidationError[]`). Lets consumers iterate
 * field-level errors without `as any`:
 *
 * ```ts
 * if (isHttpValidationError(err)) {
 *   for (const issue of err.errorBody.detail ?? []) {
 *     console.log(issue.loc, issue.msg)
 *   }
 * }
 * ```
 */
export declare function isHttpValidationError(err: unknown): err is AmigoErrorWithBody<HttpValidationErrorBody>;
/**
 * True when `err.errorBody` is the default FastAPI HTTPException shape
 * (`{ detail: string | object | array }`, possibly with `error_code` /
 * `request_id`). This is the most common error body across platform-api.
 */
export declare function isHttpException(err: unknown): err is AmigoErrorWithBody<HttpExceptionBody>;
/**
 * True when the response body could not be parsed as JSON (or was empty).
 * `err.errorBody.raw_body` is the verbatim text (truncated to 8 KB).
 */
export declare function isUnparseableErrorBody(err: unknown): err is AmigoErrorWithBody<UnparseableErrorBody>;
//# sourceMappingURL=errors.d.ts.map