/** * Error classes used in the OpenRouter Kit library. * All custom errors inherit from the base class `OpenRouterError`. * Includes a `mapError` function to standardize various error types. */ /** * Standardized error codes for classifying issues. */ export declare enum ErrorCode { /** Error response from the OpenRouter API (HTTP status >= 400). */ API_ERROR = "api_error", /** Data validation failed (config, arguments, response schema). */ VALIDATION_ERROR = "validation_error", /** Network issue connecting to the API (e.g., DNS, connection refused). */ NETWORK_ERROR = "network_error", /** Authentication failed (e.g., invalid API key, missing auth header). Status 401. */ AUTHENTICATION_ERROR = "authentication_error", /** Authorization failed (e.g., invalid/expired JWT, bad signature). Status 401/403. */ AUTHORIZATION_ERROR = "authorization_error", /** Access denied (authenticated but lacks permissions). Status 403. */ ACCESS_DENIED_ERROR = "access_denied", /** Error during the execution of a tool's `execute` function. */ TOOL_ERROR = "tool_error", /** API rate limit exceeded. Status 429. */ RATE_LIMIT_ERROR = "rate_limit_error", /** Request timed out waiting for API response. Status 408 or network timeout. */ TIMEOUT_ERROR = "timeout_error", /** Invalid library or component configuration. */ CONFIG_ERROR = "config_error", /** General security-related error (e.g., failed check, policy violation). */ SECURITY_ERROR = "security_error", /** Potentially dangerous arguments detected by sanitizer. Status 400. */ DANGEROUS_ARGS = "dangerous_args", /** Error parsing a JSON string. */ JSON_PARSE_ERROR = "json_parse_error", /** Data failed validation against a JSON Schema. */ JSON_SCHEMA_ERROR = "json_schema_error", /** JWT signing error. */ JWT_SIGN_ERROR = "jwt_sign_error", /** Error during JWT validation (expired, invalid signature etc.) */ JWT_VALIDATION_ERROR = "jwt_validation_error", /** An internal error within the library code. */ INTERNAL_ERROR = "internal_error", /** Unknown or unclassified error. */ UNKNOWN_ERROR = "unknown_error" } /** * Base error class for all library-specific errors. */ export declare class OpenRouterError extends Error { /** Standardized error code for programmatic handling. */ readonly code: ErrorCode; /** Optional: HTTP status code associated with the error. */ readonly statusCode?: number; /** Optional: Additional details, context, or the original error. */ readonly details?: any; constructor(message: string, code: ErrorCode, statusCode?: number, details?: any); } /** Error returned by the OpenRouter API (status >= 400). */ export declare class APIError extends OpenRouterError { constructor(message: string, statusCode?: number, details?: any); } /** Data validation error (config, arguments, schema). */ export declare class ValidationError extends OpenRouterError { constructor(message: string, details?: any); } /** Network error during API request (connection, DNS). */ export declare class NetworkError extends OpenRouterError { constructor(message: string, details?: any); } /** Authentication error (invalid API key, missing token). Typically 401. */ export declare class AuthenticationError extends OpenRouterError { constructor(message: string, statusCode?: number, details?: any); } /** Authorization error (invalid JWT, expired token, wrong signature). Typically 401/403. */ export declare class AuthorizationError extends OpenRouterError { constructor(message: string, statusCode?: number, details?: any); } /** Access denied (authenticated but lacks permission). Typically 403. */ export declare class AccessDeniedError extends OpenRouterError { constructor(message: string, statusCode?: number, details?: any); } /** Error during tool function execution. Typically 500 (internal server error context). */ export declare class ToolError extends OpenRouterError { constructor(message: string, details?: any); } /** Rate limit exceeded. Typically 429. */ export declare class RateLimitError extends OpenRouterError { constructor(message: string, statusCode?: number, details?: any); } /** Request timed out. Typically 408. */ export declare class TimeoutError extends OpenRouterError { constructor(message: string, statusCode?: number, details?: any); } /** Invalid library configuration. Typically indicates a setup issue. */ export declare class ConfigError extends OpenRouterError { constructor(message: string, details?: any); } /** General security error (policy violation, dangerous args). Typically 400/403. */ export declare class SecurityError extends OpenRouterError { constructor(message: string, code?: string, statusCode?: number, details?: any); } /** * Maps various error types (Axios, standard Error, etc.) to a standardized OpenRouterError subclass. * * @param error - The original error object (can be of any type). * @returns An instance of OpenRouterError or one of its subclasses. */ export declare function mapError(error: any): OpenRouterError;