liuyun 062b314844
Some checks are pending
CI / backend (push) Waiting to run
CI / frontend (push) Waiting to run
feat(error): 业务错误码注册表(子模块 + openspec change + guide)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-11 22:42:18 +08:00

22 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## Why
当前业务错误都是字符串消息(`throw new BadRequestException('用户名已存在')`),无统一错误码,前端无法按 code 分支处理,fork 后各模块各自为政。需要一套「业务域 + 错误序」的错误码注册表作为单一事实源。
## What Changes
- 新增 `src/common/error-codes.ts` 错误码注册表(5 位数字 `[域码 2 位][序 3 位]`,域码集中登记)。
- 新增 `BusinessException(code, message, status)`;`AllExceptionsFilter` 识别业务码,非业务异常仍回退 `HTTP×100`。
- 迁移关键业务错误(登录/锁定/待改密/用户名冲突/租户不存在等)到注册码。
## Capabilities
### Modified Capabilities
- `shared/api-contract`: 「错误码分段」改为「业务域 + 错误序」细分段。
## Impact
- **后端**:`error-codes.ts` + `business-exception.ts`(common)、`AllExceptionsFilter` 识别业务码、auth/users/tenants 等关键 throw 迁移。
- **文档**:guide.md 补错误码注册表说明。
- 无数据/前端变更(前端仍读 `code` + `message`)。