/** * 错误严重级别 */ export declare enum ErrorSeverity { LOW = "low", MEDIUM = "medium", HIGH = "high", CRITICAL = "critical" } /** * 错误类型枚举 */ export declare enum ErrorType { BUSINESS_ERROR = "BUSINESS_ERROR", VALIDATION_ERROR = "VALIDATION_ERROR", SYSTEM_ERROR = "SYSTEM_ERROR", NETWORK_ERROR = "NETWORK_ERROR", DATABASE_ERROR = "DATABASE_ERROR", RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND", RESOURCE_CONFLICT = "RESOURCE_CONFLICT", RESOURCE_EXHAUSTED = "RESOURCE_EXHAUSTED", PERMISSION_DENIED = "PERMISSION_DENIED", AUTHENTICATION_FAILED = "AUTHENTICATION_FAILED", CONFIG_ERROR = "CONFIG_ERROR", CONFIG_VALIDATION_ERROR = "CONFIG_VALIDATION_ERROR" } /** * 错误上下文接口 */ export interface ErrorContext { [key: string]: any; timestamp?: Date; userId?: string; channelId?: string; messageId?: string; operation?: string; stackTrace?: string; } /** * 基础错误类 */ export declare abstract class BaseError extends Error { readonly code: string; readonly type: ErrorType; readonly severity: ErrorSeverity; readonly context: ErrorContext; readonly timestamp: Date; readonly id: string; constructor(message: string, code: string, type: ErrorType, severity?: ErrorSeverity, context?: ErrorContext, cause?: Error); private generateErrorId; /** * 转换为日志格式 */ toLogFormat(): string; /** * 转换为用户友好的消息 */ abstract toUserMessage(): string; } /** * 业务错误 */ export declare class BusinessError extends BaseError { constructor(message: string, code?: string, context?: ErrorContext, severity?: ErrorSeverity); toUserMessage(): string; } /** * 验证错误 */ export declare class ValidationError extends BaseError { readonly violations: ValidationViolation[]; constructor(message: string, violations?: ValidationViolation[], context?: ErrorContext); toUserMessage(): string; } export interface ValidationViolation { field: string; value?: any; message: string; code?: string; } /** * 系统错误 */ export declare class SystemError extends BaseError { constructor(message: string, code?: string, context?: ErrorContext, cause?: Error); toUserMessage(): string; } /** * 资源错误 */ export declare class ResourceError extends BaseError { readonly resourceType: string; readonly resourceId?: string; constructor(message: string, resourceType: string, resourceId?: string, type?: ErrorType, context?: ErrorContext); toUserMessage(): string; } /** * 网络错误 */ export declare class NetworkError extends BaseError { readonly statusCode?: number; readonly url?: string; constructor(message: string, statusCode?: number, url?: string, context?: ErrorContext, cause?: Error); toUserMessage(): string; } /** * 配置错误 */ export declare class ConfigError extends BaseError { readonly configKey?: string; readonly configValue?: any; constructor(message: string, configKey?: string, configValue?: any, context?: ErrorContext); toUserMessage(): string; } /** * 错误处理器接口 */ export interface ErrorHandler { handle(error: BaseError): Promise | void; canHandle(error: BaseError): boolean; } /** * 全局错误管理器 */ export declare class ErrorManager { private static instance; private handlers; private errorHistory; private maxHistorySize; private constructor(); static getInstance(): ErrorManager; /** * 注册错误处理器 */ registerHandler(handler: ErrorHandler): void; /** * 处理错误 */ handleError(error: Error | BaseError): Promise; /** * 转换为 BaseError */ private toBaseError; /** * 添加到历史记录 */ private addToHistory; /** * 获取错误历史 */ getErrorHistory(filter?: { type?: ErrorType; severity?: ErrorSeverity; since?: Date; }): BaseError[]; /** * 清理错误历史 */ clearHistory(): void; } /** * 错误包装器 */ export declare function wrapError(error: Error, type: ErrorType, context?: ErrorContext): BaseError; /** * 断言工具 */ export declare function assert(condition: boolean, message: string, errorType?: ErrorType): asserts condition; /** * 断言非空 */ export declare function assertNotNull(value: T | null | undefined, name: string): asserts value is T; /** * 断言存在 */ export declare function assertExists(value: T | null | undefined, resourceType: string, resourceId?: string): asserts value is T;