import { ERROR_MESSAGES, type ErrorCode, httpStatusOf } from '@lingxi/shared'; export interface AppExceptionOptions { code: ErrorCode; message?: string; details?: unknown; } /** * 业务异常:由统一异常过滤器序列化为 { code, message, details, trace_id }。 * 业务代码禁止直接 throw new Error 表达可预期错误。 */ export class AppException extends Error { readonly code: ErrorCode; readonly status: number; readonly details?: unknown; constructor(options: AppExceptionOptions) { super(options.message ?? ERROR_MESSAGES[options.code]); this.name = 'AppException'; this.code = options.code; this.status = httpStatusOf(options.code); this.details = options.details; } }