UNPKG

mcp-server-logzio

Version:

Model Context Protocol server for Logz.io log management platform

147 lines 4.14 kB
/** * Base error class for MCP Logz.io server errors */ export class LogzioError extends Error { code; context; constructor(message, code, context) { super(message); this.name = this.constructor.name; this.code = code; if (context) { this.context = context; } Error.captureStackTrace(this, this.constructor); } toJSON() { return { name: this.name, message: this.message, code: this.code, context: this.context, }; } } /** * Configuration-related errors */ export class ConfigurationError extends LogzioError { constructor(message, context) { super(message, 'CONFIGURATION_ERROR', context); } } /** * API-related errors */ export class ApiError extends LogzioError { statusCode; response; constructor(message, statusCode, response, context) { super(message, 'API_ERROR', context); if (statusCode !== undefined) { this.statusCode = statusCode; } if (response !== undefined) { this.response = response; } } static fromResponse(response, context) { const message = getApiErrorMessage(response.status, response.data); return new ApiError(message, response.status, response.data, context); } } /** * Authentication-related errors */ export class AuthenticationError extends LogzioError { constructor(message, context) { super(message, 'AUTHENTICATION_ERROR', context); } } /** * Rate limiting errors */ export class RateLimitError extends LogzioError { retryAfter; constructor(message, retryAfter, context) { super(message, 'RATE_LIMIT_ERROR', context); if (retryAfter !== undefined) { this.retryAfter = retryAfter; } } } /** * Validation-related errors */ export class ValidationError extends LogzioError { field; constructor(message, field, context) { super(message, 'VALIDATION_ERROR', context); if (field !== undefined) { this.field = field; } } } /** * Tool execution errors */ export class ToolError extends LogzioError { toolName; constructor(message, toolName, context) { super(message, 'TOOL_ERROR', { toolName, ...context }); this.toolName = toolName; } } /** * Generate appropriate error message based on API response */ function getApiErrorMessage(statusCode, data) { switch (statusCode) { case 400: return 'Bad request: Please check your query parameters and format'; case 401: return 'Unauthorized: Please check your API key'; case 403: return 'Forbidden: You do not have permission to access this resource'; case 404: return 'Not found: The requested resource was not found'; case 429: return 'Rate limit exceeded: Please wait before making more requests'; case 500: return 'Internal server error: Logz.io service is experiencing issues'; case 502: case 503: case 504: return 'Service unavailable: Logz.io service is temporarily unavailable'; default: return `API request failed with status ${statusCode}`; } } /** * Check if error is retryable */ export function isRetryableError(error) { if (error instanceof ApiError) { // Retry on 5xx errors and rate limits return ((error.statusCode !== undefined && error.statusCode >= 500) || error instanceof RateLimitError); } // Retry on network errors if (error instanceof Error) { return (error.message.includes('ECONNRESET') || error.message.includes('ENOTFOUND') || error.message.includes('ECONNREFUSED') || error.message.includes('timeout')); } return false; } /** * Extract retry delay from error */ export function getRetryDelay(error) { if (error instanceof RateLimitError) { return error.retryAfter; } return undefined; } //# sourceMappingURL=errors.js.map