@rhofkens/mcp-quotes-server-claude-code
Version:
Model Context Protocol (MCP) server for managing and serving quotes
143 lines • 4.01 kB
TypeScript
/**
* Comprehensive Error Handling Utilities
*
* Advanced error handling with retry logic, structured responses, and debugging capabilities
*/
import { BaseError, ErrorCode } from './errors.js';
/**
* Configuration for retry logic
*/
export interface IRetryConfig {
maxRetries: number;
initialDelay: number;
maxDelay: number;
backoffMultiplier: number;
retryableErrors?: ErrorCode[];
onRetry?: (error: Error, attempt: number) => void;
}
/**
* Default retry configuration
*/
export declare const DEFAULT_RETRY_CONFIG: IRetryConfig;
/**
* Structured error response format
*/
export interface IStructuredErrorResponse {
error: {
code: string;
message: string;
userMessage: string;
timestamp: string;
requestId?: string;
details?: Record<string, unknown>;
context?: IErrorContext;
recovery?: IErrorRecovery;
};
}
/**
* Error context information for debugging
*/
export interface IErrorContext {
operation: string;
input?: Record<string, unknown>;
environment?: {
nodeVersion: string;
platform: string;
timestamp: string;
};
stackTrace?: string[];
relatedErrors?: Array<{
code: string;
message: string;
timestamp: string;
}>;
}
/**
* Error recovery suggestions
*/
export interface IErrorRecovery {
suggestions: string[];
retryable: boolean;
retryAfter?: number;
alternativeActions?: string[];
documentation?: string;
}
/**
* Error context builder
*/
export declare class ErrorContextBuilder {
private context;
setOperation(operation: string): this;
setInput(input: Record<string, unknown>): this;
setEnvironment(): this;
setStackTrace(error: Error): this;
addRelatedError(code: string, message: string): this;
build(): IErrorContext;
}
/**
* Generate recovery suggestions based on error type
*/
export declare function generateRecoverySuggestions(error: BaseError): IErrorRecovery;
/**
* Create a structured error response
*/
export declare function createStructuredError(error: unknown, context?: IErrorContext, requestId?: string): IStructuredErrorResponse;
/**
* Retry logic with exponential backoff
*/
export declare function withRetry<T>(operation: () => Promise<T>, config?: Partial<IRetryConfig>): Promise<T>;
/**
* Enhanced error logger with context
*/
export declare function logError(error: unknown, context?: Partial<IErrorContext>, severity?: 'error' | 'warn' | 'fatal'): void;
/**
* Circuit breaker pattern for API calls
*/
export declare class CircuitBreaker {
private readonly threshold;
private readonly resetTimeout;
private failures;
private lastFailureTime;
private state;
constructor(threshold?: number, _breakerTimeout?: number, // 1 minute (unused but kept for compatibility)
resetTimeout?: number);
execute<T>(operation: () => Promise<T>): Promise<T>;
private onSuccess;
private onFailure;
getState(): string;
reset(): void;
}
/**
* Error aggregator for batch operations
*/
export declare class ErrorAggregator {
private errors;
add(error: Error, context?: unknown): void;
hasErrors(): boolean;
getErrors(): Array<{
error: Error;
context?: unknown;
}>;
clear(): void;
/**
* Throw an aggregated error if any errors exist
*/
throwIfAny(message: string): void;
}
/**
* Timeout wrapper for async operations
*/
export declare function withTimeout<T>(operation: Promise<T>, timeoutMs: number, errorMessage?: string): Promise<T>;
/**
* Error boundary for async operations
*/
export declare function errorBoundary<T>(operation: () => Promise<T>, fallback?: T, onError?: (error: Error) => void): Promise<T | undefined>;
/**
* Create a request ID for tracking
*/
export declare function generateRequestId(): string;
/**
* Export all error types for convenience
*/
export * from './errors.js';
//# sourceMappingURL=errorHandling.d.ts.map