22 lines
1.1 KiB
Markdown
22 lines
1.1 KiB
Markdown
## 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`)。
|