UNPKG

@spaik/mcp-server-roi

Version:

MCP server for AI ROI prediction and tracking with Monte Carlo simulations

129 lines 3.61 kB
/** * Custom error types for MCP Server ROI */ export class BaseError extends Error { code; statusCode; isOperational; context; constructor(message, code, statusCode, isOperational = true, context) { super(message); this.name = this.constructor.name; this.code = code; this.statusCode = statusCode; this.isOperational = isOperational; this.context = context; Error.captureStackTrace(this, this.constructor); } } /** * Validation errors for input data */ export class ValidationError extends BaseError { constructor(message, context) { super(message, 'VALIDATION_ERROR', 400, true, context); } } /** * Database-related errors */ export class DatabaseError extends BaseError { constructor(message, context) { super(message, 'DATABASE_ERROR', 500, false, context); } } /** * Worker thread errors */ export class WorkerError extends BaseError { constructor(message, context) { super(message, 'WORKER_ERROR', 500, false, context); } } /** * Calculation errors (e.g., IRR convergence failure) */ export class CalculationError extends BaseError { constructor(message, context) { super(message, 'CALCULATION_ERROR', 422, true, context); } } /** * Configuration errors */ export class ConfigurationError extends BaseError { constructor(message, context) { super(message, 'CONFIGURATION_ERROR', 500, false, context); } } /** * Resource not found errors */ export class NotFoundError extends BaseError { constructor(resource, identifier) { super(`${resource} not found: ${identifier}`, 'NOT_FOUND', 404, true, { resource, identifier }); } } /** * Rate limiting errors */ export class RateLimitError extends BaseError { constructor(limit, window) { super(`Rate limit exceeded: ${limit} requests per ${window}`, 'RATE_LIMIT_EXCEEDED', 429, true, { limit, window }); } } /** * Timeout errors */ export class TimeoutError extends BaseError { constructor(operation, timeoutMs) { super(`Operation timed out: ${operation} (${timeoutMs}ms)`, 'TIMEOUT_ERROR', 408, true, { operation, timeoutMs }); } } /** * Input validation specific errors */ export class InputValidationError extends ValidationError { constructor(field, value, reason) { super(`Invalid input for field '${field}': ${reason}`, { field, value, reason }); } } /** * Range validation errors */ export class RangeError extends ValidationError { constructor(field, value, min, max) { const constraints = []; if (min !== undefined) constraints.push(`min: ${min}`); if (max !== undefined) constraints.push(`max: ${max}`); super(`Value ${value} for field '${field}' is out of range (${constraints.join(', ')})`, { field, value, min, max }); } } /** * Type guard to check if an error is operational */ export function isOperationalError(error) { return error instanceof BaseError && error.isOperational; } /** * Error serializer for API responses */ export function serializeError(error) { const serialized = { name: error.name, message: error.message }; if (error instanceof BaseError) { serialized.code = error.code; serialized.statusCode = error.statusCode; serialized.context = error.context; } // Include stack trace in development if (process.env.NODE_ENV !== 'production') { serialized.stack = error.stack; } return serialized; } //# sourceMappingURL=errors.js.map