/** * # Service Error Types * * Standardized error handling for service layer with error codes and context. * * ## Business Perspective * Provides consistent error reporting across all services, enabling better * debugging, logging, and user-facing error messages. 🔒 * * @packageDocumentation */ /** * Error codes for service operations * * Note: The numeric ranges in comments (e.g., 1000-1999) are organizational * categories for documentation purposes. The actual enum values are strings. */ export declare enum ServiceErrorCode { VALIDATION_ERROR = "VALIDATION_ERROR", INVALID_SECURITY_LEVEL = "INVALID_SECURITY_LEVEL", INVALID_COMPONENT_TYPE = "INVALID_COMPONENT_TYPE", INVALID_INPUT = "INVALID_INPUT", MISSING_REQUIRED_FIELD = "MISSING_REQUIRED_FIELD", DATA_NOT_FOUND = "DATA_NOT_FOUND", DATA_PROVIDER_ERROR = "DATA_PROVIDER_ERROR", CONFIGURATION_ERROR = "CONFIGURATION_ERROR", CALCULATION_ERROR = "CALCULATION_ERROR", COMPLIANCE_CHECK_ERROR = "COMPLIANCE_CHECK_ERROR", ROI_CALCULATION_ERROR = "ROI_CALCULATION_ERROR", NETWORK_ERROR = "NETWORK_ERROR", CONNECTION_ERROR = "CONNECTION_ERROR", TIMEOUT_ERROR = "TIMEOUT_ERROR", RETRYABLE_ERROR = "RETRYABLE_ERROR", RATE_LIMIT_ERROR = "RATE_LIMIT_ERROR", INTERNAL_ERROR = "INTERNAL_ERROR", UNEXPECTED_ERROR = "UNEXPECTED_ERROR" } /** * Context information for errors */ export interface ErrorContext { /** Service that generated the error */ service?: string; /** Method that generated the error */ method?: string; /** Component being processed */ component?: string; /** Security level being processed */ level?: string; /** Additional context information */ [key: string]: unknown; } /** * Custom error class for service operations * * Provides structured error information with error codes and context * for better debugging and error handling. */ export declare class ServiceError extends Error { /** * Error code for categorization */ readonly code: ServiceErrorCode; /** * Context information about the error */ readonly context: ErrorContext; /** * Original error that caused this error (if any) */ readonly cause?: Error; /** * Timestamp when the error occurred */ readonly timestamp: Date; /** * Create a new ServiceError * * @param message - Human-readable error message * @param code - Error code for categorization * @param context - Additional context information * @param cause - Original error that caused this error */ constructor(message: string, code?: ServiceErrorCode, context?: ErrorContext, cause?: Error); /** * Get a formatted error message with context * * @returns Formatted error message */ getFormattedMessage(): string; /** * Serialize error cause for JSON output * * @returns Serialized cause or undefined */ private serializeCause; /** * Convert error to JSON for logging * * @returns JSON representation of the error */ toJSON(): Record; } /** * Create a validation error * * @param message - Error message * @param context - Error context * @returns ServiceError instance */ export declare function createValidationError(message: string, context?: ErrorContext): ServiceError; /** * Create a data not found error * * @param message - Error message * @param context - Error context * @returns ServiceError instance */ export declare function createDataNotFoundError(message: string, context?: ErrorContext): ServiceError; /** * Create a calculation error * * @param message - Error message * @param context - Error context * @param cause - Original error * @returns ServiceError instance */ export declare function createCalculationError(message: string, context?: ErrorContext, cause?: Error): ServiceError; /** * Type guard to check if an error is a ServiceError * * @param error - Error to check * @returns True if error is a ServiceError */ export declare function isServiceError(error: unknown): error is ServiceError; /** * Extract error message from unknown error type * * @param error - Error to extract message from * @returns Error message string */ export declare function getErrorMessage(error: unknown): string; /** * Create a validation error using ServiceError * * @param message - Error message * @param field - Optional field name that failed validation * @param context - Additional error context * @returns ServiceError instance */ export declare function createValidationServiceError(message: string, field?: string, context?: ErrorContext): ServiceError; /** * Create a network error using ServiceError * * @param message - Error message * @param statusCode - Optional HTTP status code * @param context - Additional error context * @returns ServiceError instance */ export declare function createNetworkServiceError(message: string, statusCode?: number, context?: ErrorContext): ServiceError; /** * Create a retryable error using ServiceError * * @param message - Error message * @param retryAfter - Optional retry delay in seconds * @param context - Additional error context * @returns ServiceError instance */ export declare function createRetryableServiceError(message: string, retryAfter?: number, context?: ErrorContext): ServiceError; /** * Check if error is validation related */ export declare function isValidationError(error: unknown): boolean; /** * Check if error is network related */ export declare function isNetworkError(error: unknown): boolean; /** * Check if error is retryable */ export declare function isRetryableError(error: unknown): boolean; //# sourceMappingURL=errors.d.ts.map