/** * Comprehensive error handling system for Evolution API MCP Server * * This module provides: * - Error type definitions and classes * - HTTP status code to user-friendly message mapping * - Authentication failure handling * - Timeout and network error handling with retry suggestions * - Validation error messages with parameter correction hints * - Error logging and debugging information */ import { z } from 'zod'; /** * Error types for different categories of errors */ export declare enum ErrorType { CONFIGURATION_ERROR = "CONFIGURATION_ERROR", AUTHENTICATION_ERROR = "AUTHENTICATION_ERROR", API_ERROR = "API_ERROR", NETWORK_ERROR = "NETWORK_ERROR", VALIDATION_ERROR = "VALIDATION_ERROR", TIMEOUT_ERROR = "TIMEOUT_ERROR", RATE_LIMIT_ERROR = "RATE_LIMIT_ERROR", INSTANCE_ERROR = "INSTANCE_ERROR", PERMISSION_ERROR = "PERMISSION_ERROR", RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND", INTERNAL_ERROR = "INTERNAL_ERROR" } /** * Error severity levels for logging and handling */ export declare enum ErrorSeverity { LOW = "LOW", MEDIUM = "MEDIUM", HIGH = "HIGH", CRITICAL = "CRITICAL" } /** * Base error interface */ export interface BaseError { type: ErrorType; message: string; code?: string; statusCode?: number; severity: ErrorSeverity; timestamp: Date; details?: any; suggestions?: string[]; retryable: boolean; context?: ErrorContext; } /** * Error context for debugging and logging */ export interface ErrorContext { operation?: string; endpoint?: string; instance?: string; parameters?: any; requestId?: string; userId?: string; stackTrace?: string; } /** * Validation error details */ export interface ValidationErrorDetail { field: string; value: any; message: string; code: string; suggestion?: string; } /** * Network error details */ export interface NetworkErrorDetail { url?: string; timeout?: number; retryAttempt?: number; maxRetries?: number; nextRetryIn?: number; } /** * Base error class with comprehensive error information */ export declare class McpError extends Error implements BaseError { readonly type: ErrorType; readonly code?: string; readonly statusCode?: number; readonly severity: ErrorSeverity; readonly timestamp: Date; readonly details?: any; readonly suggestions: string[]; readonly retryable: boolean; readonly context?: ErrorContext; constructor(type: ErrorType, message: string, options?: { code?: string; statusCode?: number; severity?: ErrorSeverity; details?: any; suggestions?: string[]; retryable?: boolean; context?: ErrorContext; cause?: Error; }); private getDefaultSeverity; private getDefaultRetryable; /** * Convert error to JSON for logging and API responses */ toJSON(): Record; /** * Get user-friendly error message for Claude Desktop */ getUserMessage(): string; } /** * Specific error classes for different error types */ export declare class ConfigurationError extends McpError { constructor(message: string, options?: Omit[2], 'type'>); } export declare class AuthenticationError extends McpError { constructor(message: string, options?: Omit[2], 'type'>); } export declare class ValidationError extends McpError { readonly validationDetails: ValidationErrorDetail[]; constructor(message: string, validationDetails?: ValidationErrorDetail[], options?: Omit[2], 'type'>); } export declare class NetworkError extends McpError { readonly networkDetails: NetworkErrorDetail; constructor(message: string, networkDetails?: NetworkErrorDetail, options?: Omit[2], 'type'>); } export declare class TimeoutError extends McpError { constructor(message: string, timeout: number, options?: Omit[2], 'type'>); } export declare class RateLimitError extends McpError { constructor(message: string, retryAfter?: number, options?: Omit[2], 'type'>); } export declare class InstanceError extends McpError { constructor(message: string, instanceName?: string, options?: Omit[2], 'type'>); } /** * HTTP status code to error type mapping */ export declare const HTTP_STATUS_ERROR_MAP: Record string; getSuggestions: (status: number, data?: any) => string[]; }>; /** * Error handler class for comprehensive error processing */ export declare class ErrorHandler { private enableLogging; private logLevel; constructor(options?: { enableLogging?: boolean; logLevel?: 'error' | 'warn' | 'info' | 'debug'; }); /** * Handle HTTP errors from axios responses */ handleHttpError(error: any, context?: ErrorContext): McpError; /** * Handle axios-specific errors */ private handleAxiosError; /** * Extract validation details from error response */ private extractValidationDetails; /** * Generate validation suggestions based on field and error */ private getValidationSuggestion; /** * Handle validation errors from Zod schemas */ handleValidationError(zodError: z.ZodError, context?: ErrorContext): ValidationError; /** * Generate suggestions for Zod validation errors */ private getZodValidationSuggestion; /** * Log error with appropriate level */ logError(error: McpError): void; /** * Create error response for MCP tools */ createToolErrorResponse(error: McpError): { success: false; error: { type: string; message: string; code?: string; suggestions?: string[]; retryable: boolean; }; }; /** * Create success response for MCP tools */ createToolSuccessResponse(data: T): { success: true; data: T; }; } /** * Global error handler instance */ export declare const globalErrorHandler: ErrorHandler; /** * Utility functions for common error scenarios */ export declare const ErrorUtils: { /** * Create configuration error */ configurationError(message: string, suggestions?: string[]): ConfigurationError; /** * Create authentication error */ authenticationError(message?: string): AuthenticationError; /** * Create validation error from Zod error */ validationError(zodError: z.ZodError, context?: ErrorContext): ValidationError; /** * Create instance error */ instanceError(instanceName: string, message?: string): InstanceError; /** * Create network error */ networkError(message: string, url?: string): NetworkError; /** * Create timeout error */ timeoutError(timeout: number): TimeoutError; /** * Create rate limit error */ rateLimitError(retryAfter?: number): RateLimitError; };