@rhofkens/mcp-quotes-server-claude-code
Version:
Model Context Protocol (MCP) server for managing and serving quotes
136 lines • 4.23 kB
TypeScript
/**
* Error Handling Utilities
*
* Custom error classes and error handling utilities for the MCP Quotes Server
*/
/**
* Error codes for categorizing different error types
*/
export declare enum ErrorCode {
UNKNOWN_ERROR = "UNKNOWN_ERROR",
INTERNAL_ERROR = "INTERNAL_ERROR",
VALIDATION_ERROR = "VALIDATION_ERROR",
INVALID_INPUT = "INVALID_INPUT",
MISSING_PARAMETER = "MISSING_PARAMETER",
TYPE_MISMATCH = "TYPE_MISMATCH",
API_ERROR = "API_ERROR",
API_TIMEOUT = "API_TIMEOUT",
API_RATE_LIMIT = "API_RATE_LIMIT",
API_UNAUTHORIZED = "API_UNAUTHORIZED",
API_NOT_FOUND = "API_NOT_FOUND",
CONFIG_ERROR = "CONFIG_ERROR",
MISSING_ENV_VAR = "MISSING_ENV_VAR",
INVALID_CONFIG = "INVALID_CONFIG",
MCP_ERROR = "MCP_ERROR",
MCP_METHOD_NOT_FOUND = "MCP_METHOD_NOT_FOUND",
MCP_INVALID_PARAMS = "MCP_INVALID_PARAMS",
MCP_INTERNAL_ERROR = "MCP_INTERNAL_ERROR",
RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND",
RESOURCE_UNAVAILABLE = "RESOURCE_UNAVAILABLE"
}
/**
* Base error class for all custom errors
*/
export declare class BaseError extends Error {
code: ErrorCode;
statusCode: number;
details?: Record<string, unknown> | undefined;
constructor(message: string, code: ErrorCode, statusCode?: number, details?: Record<string, unknown> | undefined);
/**
* Convert error to JSON representation
*/
toJSON(): Record<string, unknown>;
/**
* Get user-friendly error message
*/
getUserMessage(): string;
}
/**
* MCP protocol specific errors
*/
export declare class MCPError extends BaseError {
constructor(message: string, code?: ErrorCode, details?: Record<string, unknown>);
getUserMessage(): string;
}
/**
* Validation errors for input validation failures
*/
export declare class ValidationError extends BaseError {
field?: string | undefined;
constructor(message: string, field?: string | undefined, details?: Record<string, unknown>);
getUserMessage(): string;
}
/**
* API errors for external service failures
*/
export declare class APIError extends BaseError {
service?: string | undefined;
constructor(message: string, code?: ErrorCode, service?: string | undefined, details?: Record<string, unknown>);
private static getStatusCodeForErrorCode;
getUserMessage(): string;
}
/**
* Configuration errors
*/
export declare class ConfigError extends BaseError {
variable?: string | undefined;
constructor(message: string, variable?: string | undefined, details?: Record<string, unknown>);
getUserMessage(): string;
}
/**
* Network errors for connectivity issues
*/
export declare class NetworkError extends APIError {
constructor(message: string, service?: string, details?: Record<string, unknown>);
getUserMessage(): string;
}
/**
* Authentication errors for API key issues
*/
export declare class AuthenticationError extends APIError {
constructor(message: string, service?: string, details?: Record<string, unknown>);
getUserMessage(): string;
}
/**
* Rate limit errors
*/
export declare class RateLimitError extends APIError {
constructor(message: string, service?: string, details?: Record<string, unknown>);
getUserMessage(): string;
}
/**
* Error formatter for consistent error messages
*/
export declare class ErrorFormatter {
/**
* Format error for logging
*/
static formatForLog(error: Error): string;
/**
* Format error for user display
*/
static formatForUser(error: Error): string;
/**
* Extract error details for debugging
*/
static extractDetails(error: unknown): Record<string, unknown>;
}
/**
* Wrap an error with additional context
*/
export declare function wrapError(error: unknown, message: string, code?: ErrorCode): BaseError;
/**
* Type guard to check if error is a BaseError
*/
export declare function isBaseError(error: unknown): error is BaseError;
/**
* Type guard to check if error has a code property
*/
export declare function hasErrorCode(error: unknown): error is {
code: string;
};
/**
* Convert unknown error to BaseError
*/
export declare function toBaseError(error: unknown): BaseError;
//# sourceMappingURL=errors.d.ts.map