deepsource-mcp-server
Version:
Model Context Protocol server for DeepSource
72 lines (71 loc) • 2.52 kB
TypeScript
/**
* @fileoverview Error utilities for handling API errors
* This module provides utilities for classifying and handling errors.
*/
/**
* Possible error categories for API errors
* @enum {string}
*/
export declare enum ErrorCategory {
/** Error related to authentication or authorization */
AUTH = "AUTH",
/** Error with network connectivity */
NETWORK = "NETWORK",
/** Error with server processing */
SERVER = "SERVER",
/** Error with client input */
CLIENT = "CLIENT",
/** Error with request timing out */
TIMEOUT = "TIMEOUT",
/** Error with rate limiting */
RATE_LIMIT = "RATE_LIMIT",
/** Error with the GraphQL schema */
SCHEMA = "SCHEMA",
/** Error with data not found */
NOT_FOUND = "NOT_FOUND",
/** Error with data formatting */
FORMAT = "FORMAT",
/** Other uncategorized errors */
OTHER = "OTHER"
}
/**
* Enriched error with additional metadata
* Extends the standard Error with additional properties for better error handling.
* @interface
*/
export interface ClassifiedError extends Error {
/** The category of the error */
category: ErrorCategory;
/** The original error that caused this error */
originalError?: unknown;
/** Any additional metadata related to the error */
metadata?: Record<string, unknown>;
}
/**
* Create a new classified error with additional metadata
* @param message The error message
* @param category The error category
* @param originalError The original error that caused this error, useful for debugging and error tracing
* @param metadata Additional contextual information about the error as key-value pairs
* @returns A new classified error with the specified properties
* @example
* const error = createClassifiedError(
* 'Failed to fetch project data',
* ErrorCategory.NETWORK,
* originalError,
* { projectId: '123', endpoint: '/api/projects' }
* );
*/
export declare function createClassifiedError(message: string, category: ErrorCategory, originalError?: unknown, metadata?: Record<string, unknown>): ClassifiedError;
/**
* Check if an error is a classified error
* @param error The error to check
* @returns True if the error is a classified error
*/
export declare function isClassifiedError(error: unknown): error is ClassifiedError;
/**
* Error classifier for GraphQL errors
* @param error The error to classify
* @returns The classified error category
*/
export declare function classifyGraphQLError(error: Error): ErrorCategory;