主题
错误码段
1. 编码规则
错误码为 10 位数字:类型(1) + 系统(3) + 模块(3) + 错误码(3),例如 1002000011。
- 类型:1 = 业务异常。
- 系统:固定占位,当前为
002。 - 模块:由
ServiceErrorCodeRange统一分配,模块之间不得重叠。 - 错误码:模块内部自增。
2. 已分配区段
| 模块 | 区间(段内前缀) |
|---|---|
| infra | 1-001-000-000 起 |
| system | 1-002-000-000 起 |
| report | 1-003-000-000 起 |
| member | 1-004-000-000 起 |
| mp | 1-006-000-000 起 |
| pay | 1-007-000-000 起 |
| product | 1-008-000-000 起 |
| bpm | 1-009-000-000 起 |
| trade | 1-011-000-000 起 |
| promotion | 1-013-000-000 起 |
| crm | 1-020-000-000 起 |
| ai | 1-022-000-000 起 |
新增模块前先在本表登记,再写
ErrorCodeConstants,否则会与既有模块冲突。
3. 使用方式
- 模块内定义
ErrorCodeConstants,每个错误码一个常量。 - 抛
ServiceException,用ServiceExceptionUtil.exception(...)构造。 - 全局异常处理器把
ErrorCode渲染为CommonResult.code/message。 - 前端按
code做本地化提示,不解析message文案。