/** * API error classes * * Errors thrown when the API returns error responses. * Includes specific error types for common scenarios. */ import { TRPCClientError } from "@trpc/client"; import { ComplianceError, type ComplianceErrorOptions } from "./base"; /** * Error thrown when the API returns an error response. * * @example * ```typescript * try { * await sdk.clients.create({ ... }); * } catch (error) { * if (error instanceof APIError) { * console.log("Status:", error.statusCode); * console.log("Code:", error.code); * } * } * ``` */ export declare class APIError extends ComplianceError { /** * HTTP status code (if available) */ readonly statusCode?: number; constructor(message: string, code: string, options?: ComplianceErrorOptions & { statusCode?: number; }); } /** * Resource not found error (404). * * @example * ```typescript * try { * await sdk.clients.retrieve("invalid-id"); * } catch (error) { * if (error instanceof NotFoundError) { * console.log(`${error.resourceType} '${error.resourceId}' not found`); * } * } * ``` */ export declare class NotFoundError extends APIError { /** * Type of resource that was not found (e.g., "Client", "Transaction") */ readonly resourceType: string; /** * ID of the resource that was not found */ readonly resourceId: string; constructor(resourceType: string, resourceId: string, requestId?: string); } /** * Authentication failed error (401). * Thrown when the API key is invalid or missing. */ export declare class UnauthorizedError extends APIError { constructor(message?: string, requestId?: string); } /** * Permission denied error (403). * Thrown when the API key lacks permission for the operation. * * @example * ```typescript * // Using test API key with live environment * const sdk = new ComplianceSDK({ * apiKey: "sk_test_...", * environment: "live", // No permission! * }); * ``` */ export declare class ForbiddenError extends APIError { constructor(message?: string, requestId?: string); } /** * Organization mismatch error (403). * * Thrown when the client-asserted `X-Organization-ID` no longer matches the * organization of the authenticated session — typically a stale browser tab * after the user switched organizations in another tab. This is an expected, * transient condition, not a permissions failure; host applications should * recover by re-syncing to the session's current organization rather than * surfacing it as an error. * * Subclasses `ForbiddenError` so existing `instanceof ForbiddenError` handling * continues to work. */ export declare class OrganizationMismatchError extends ForbiddenError { constructor(message?: string, requestId?: string); } /** * Rate limit exceeded error (429). * Includes retry information when available. * * @example * ```typescript * try { * await sdk.clients.list(); * } catch (error) { * if (error instanceof RateLimitError) { * console.log(`Rate limited. Retry after ${error.retryAfter}s`); * await sleep(error.retryAfter * 1000); * // Retry... * } * } * ``` */ export declare class RateLimitError extends APIError { /** * Seconds to wait before retrying (if provided by API) */ readonly retryAfter?: number; constructor(retryAfter?: number, requestId?: string); } /** * Server error (5xx). * Indicates an unexpected error on the API server. */ export declare class ServerError extends APIError { constructor(message?: string, requestId?: string); } /** * Network/connection error. * Thrown when the request fails to reach the server. */ export declare class NetworkError extends APIError { constructor(message?: string, cause?: Error); } /** * Request timeout error. * Thrown when the request exceeds the configured timeout. */ export declare class TimeoutError extends APIError { /** * Timeout duration in milliseconds */ readonly timeout: number; constructor(timeout: number, requestId?: string); } /** * Maps a tRPC client error to an SDK-specific error. * * This function converts tRPC errors into the appropriate * SDK error class for better error handling. * * @param error - tRPC client error * @returns SDK-specific error * * @example * ```typescript * try { * await trpcClient.clients.retrieve.query({ id: "..." }); * } catch (error) { * if (isTRPCError(error)) { * throw mapTRPCError(error); * } * throw error; * } * ``` */ export declare function mapTRPCError(error: TRPCClientError): ComplianceError; /** * Type guard to check if an error is a specific API error type. * * @param error - Error to check * @param type - Error class to check against * @returns True if error is an instance of the specified type */ export declare function isAPIError(error: unknown, type?: T): error is InstanceType;