UNPKG

route-claudecode

Version:

Advanced routing and transformation system for Claude Code outputs to multiple AI providers

79 lines 2.51 kB
/** * 统一错误处理系统 * 确保所有错误都正确返回HTTP状态码,不允许静默失败 */ import { FastifyReply } from 'fastify'; export interface ErrorContext { requestId: string; providerId?: string; model?: string; stage: string; isStreaming?: boolean; retryCount?: number; maxRetries?: number; } export interface ErrorResponse { error: { type: string; message: string; code?: string; details?: any; }; } export declare class ValidationError extends Error { readonly field: string; readonly value: any; readonly constraint: string; constructor(message: string, field: string, value: any, constraint: string); } export declare class UnifiedErrorHandler { /** * 处理所有类型的错误,确保返回适当的HTTP状态码 */ static handleError(error: any, reply: FastifyReply, context: ErrorContext): void; /** * 处理streaming错误 */ private static handleStreamingError; /** * 处理常规错误 */ private static handleRegularError; /** * 分析错误并确定适当的状态码和类型 */ private static analyzeError; /** * 将HTTP状态码映射到错误类型 */ private static mapStatusCodeToType; /** * 检查错误是否应该重试 */ static shouldRetry(error: any, currentRetry: number, maxRetries: number): boolean; /** * 验证错误处理是否正确执行 */ static validateErrorHandling(error: any, reply: FastifyReply, context: ErrorContext): void; } /** * 便捷函数:处理Provider错误 */ export declare function handleProviderError(error: any, reply: FastifyReply, context: Omit<ErrorContext, 'stage'>): void; /** * 便捷函数:处理Streaming错误 */ export declare function handleStreamingError(error: any, reply: FastifyReply, context: Omit<ErrorContext, 'stage' | 'isStreaming'>): void; /** * 便捷函数:处理路由错误 */ export declare function handleRoutingError(error: any, reply: FastifyReply, context: Omit<ErrorContext, 'stage'>): void; /** * 便捷函数:处理输入处理错误 */ export declare function handleInputError(error: any, reply: FastifyReply, context: Omit<ErrorContext, 'stage'>): void; /** * 便捷函数:处理输出处理错误 */ export declare function handleOutputError(error: any, reply: FastifyReply, context: Omit<ErrorContext, 'stage'>): void; //# sourceMappingURL=error-handler.d.ts.map