refactor: 模型错误解析改为 ErrorMessageMapping 配置驱动

- parseModelError 按模型配置的 ErrorMessageMapping(schema 树)解析错误响应
- 成功判定: code 提取为空 / code 节点配置 defaultValue 且提取值等于它 → 成功
- 未配置 mapping 不识别错误(纯配置驱动), 删硬编码 ModelErrorResp/ModelError1Resp
- DTO 加 errorMessageMapping 字段, update.sql 建 error_message_mapping JSONB 列
- 单测: parse_error_test.go 覆盖扁平/嵌套/数组/纯字符串路径/未配置/坏 JSON
This commit is contained in:
2026-08-29 17:52:23 +08:00
parent 7dcfb6744d
commit 923644db2b
8 changed files with 341 additions and 35 deletions
-12
View File
@@ -59,18 +59,6 @@ type ModelCallStreamReq struct {
BusinessParams map[string]any `json:"businessParams" dc:"业务参数(按业务字段名传,按 RequestBusinessFieldMapping 写入请求体)"`
}
type ModelErrorResp struct {
Error struct {
Code string `json:"code"`
Message string `json:"message"`
} `json:"error"`
}
type ModelError1Resp struct {
Code int `json:"code"`
Message string `json:"message"`
}
type ModelMsg struct {
TaskID int64 `json:"id" dc:"任务ID"`
TotalTokens int64 `json:"totalTokens" dc:"总token"`
+2
View File
@@ -38,6 +38,7 @@ type CreateModelManageReq struct {
MinDuration int `json:"minDuration" dc:"最小时长"`
MaxDuration int `json:"maxDuration" dc:"最大时长"`
LastFrame string `json:"lastFrame" dc:"视频的尾帧图像"`
ErrorMessageMapping map[string]any `json:"errorMessageMapping" dc:"错误消息映射(schema 树,解析模型错误用)"`
}
type CreateModelManageRes struct {
@@ -73,6 +74,7 @@ type UpdateModelManageReq struct {
MinDuration int `json:"minDuration" dc:"最小时长"`
MaxDuration int `json:"maxDuration" dc:"最大时长"`
LastFrame string `json:"lastFrame" dc:"视频的尾帧图像"`
ErrorMessageMapping map[string]any `json:"errorMessageMapping" dc:"错误消息映射(schema 树,解析模型错误用)"`
}
type DeleteModelManageReq struct {