/** * 数据库相关异常 */ /** * 数据库错误基类 */ export class DatabaseError extends Error { constructor(message: string, public code?: string, public originalError?: Error) { super(message); this.name = 'DatabaseError'; Object.setPrototypeOf(this, DatabaseError.prototype); } } /** * 数据库连接错误 */ export class DatabaseConnectionError extends DatabaseError { constructor(message: string, originalError?: Error) { super(message, 'DATABASE_CONNECTION_ERROR', originalError); this.name = 'DatabaseConnectionError'; Object.setPrototypeOf(this, DatabaseConnectionError.prototype); } } /** * 数据库操作超时错误 */ export class DatabaseTimeoutError extends DatabaseError { constructor(message: string = 'Database operation timed out', originalError?: Error) { super(message, 'DATABASE_TIMEOUT_ERROR', originalError); this.name = 'DatabaseTimeoutError'; Object.setPrototypeOf(this, DatabaseTimeoutError.prototype); } } /** * 数据库查询错误 */ export class DatabaseQueryError extends DatabaseError { constructor(message: string, originalError?: Error) { super(message, 'DATABASE_QUERY_ERROR', originalError); this.name = 'DatabaseQueryError'; Object.setPrototypeOf(this, DatabaseQueryError.prototype); } }