UNPKG

mcp-talent-server

Version:

Model Context Protocol server for talent management tools

66 lines 2.05 kB
export class RAGError extends Error { code; context; constructor(message, code, context) { super(message); this.name = 'RAGError'; this.code = code; this.context = context; } } export class VectorStoreError extends RAGError { constructor(message, context) { super(message, 'VECTOR_STORE_ERROR', context); this.name = 'VectorStoreError'; } } export class ToolExecutionError extends RAGError { constructor(toolName, message, context) { super(`Tool '${toolName}' execution failed: ${message}`, 'TOOL_EXECUTION_ERROR', { toolName, ...context, }); this.name = 'ToolExecutionError'; } } export class ValidationError extends RAGError { constructor(message, context) { super(message, 'VALIDATION_ERROR', context); this.name = 'ValidationError'; } } export function handleAsyncError(operation, errorType, context) { return operation().catch((error) => { const message = error instanceof Error ? error.message : 'Unknown error occurred'; throw new errorType(message, { originalError: error, ...context }); }); } export function createErrorResponse(error, defaultMessage = 'An error occurred') { if (error instanceof RAGError) { return { error: error.message, code: error.code, context: error.context, }; } if (error instanceof Error) { return { error: error.message, code: 'UNKNOWN_ERROR', }; } return { error: defaultMessage, code: 'UNKNOWN_ERROR', }; } export function logError(error, context) { const errorInfo = { timestamp: new Date().toISOString(), error: error instanceof Error ? error.message : 'Unknown error', stack: error instanceof Error ? error.stack : undefined, context, }; console.error('RAG System Error:', JSON.stringify(errorInfo, null, 2)); } //# sourceMappingURL=error-handler.util.js.map