fix logic
This commit is contained in:
parent
5edb069bd5
commit
bdb1d7b8e1
@ -36,7 +36,7 @@ type APIRequest struct {
|
||||
// WestAPIResponse 定义西部API响应结构
|
||||
type APIResponse struct {
|
||||
SourceId string
|
||||
Resp []byte
|
||||
Resp json.RawMessage
|
||||
Success bool
|
||||
}
|
||||
|
||||
@ -159,8 +159,20 @@ func (l *COMB298YLogic) COMB298Y(req *types.Request) (resp string, err *errs.App
|
||||
respData, err := l.svcCtx.WestDexService.CallAPI(req.SourceId, req.Request, l.svcCtx.Config.WestConfig.SecretId)
|
||||
if err != nil {
|
||||
callAPIErr = err
|
||||
westResp = "{}" // 发生错误时返回空对象
|
||||
} else {
|
||||
westResp = string(respData)
|
||||
// 确保返回的是有效的 JSON
|
||||
if len(respData) == 0 {
|
||||
westResp = "{}"
|
||||
} else {
|
||||
// 验证 JSON 是否有效
|
||||
var jsonCheck interface{}
|
||||
if json.Unmarshal(respData, &jsonCheck) != nil {
|
||||
westResp = "{}"
|
||||
} else {
|
||||
westResp = string(respData)
|
||||
}
|
||||
}
|
||||
}
|
||||
case "yushan":
|
||||
respData, err := l.svcCtx.YushanService.Request(req.SourceId, req.Request)
|
||||
@ -170,11 +182,24 @@ func (l *COMB298YLogic) COMB298Y(req *types.Request) (resp string, err *errs.App
|
||||
} else {
|
||||
callAPIErr = errs.ErrSystem
|
||||
}
|
||||
westResp = "{}" // 发生错误时返回空对象
|
||||
} else {
|
||||
westResp = string(respData)
|
||||
// 确保返回的是有效的 JSON
|
||||
if len(respData) == 0 {
|
||||
westResp = "{}"
|
||||
} else {
|
||||
// 验证 JSON 是否有效
|
||||
var jsonCheck interface{}
|
||||
if json.Unmarshal(respData, &jsonCheck) != nil {
|
||||
westResp = "{}"
|
||||
} else {
|
||||
westResp = string(respData)
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
success = false
|
||||
westResp = "{}"
|
||||
logx.Errorf("未知的服务类型:%s", req.Service)
|
||||
}
|
||||
|
||||
@ -182,9 +207,15 @@ func (l *COMB298YLogic) COMB298Y(req *types.Request) (resp string, err *errs.App
|
||||
success = false
|
||||
}
|
||||
|
||||
// 确保响应是有效的 JSON
|
||||
var jsonResp json.RawMessage
|
||||
if err := json.Unmarshal([]byte(westResp), &jsonResp); err != nil {
|
||||
jsonResp = json.RawMessage("{}")
|
||||
}
|
||||
|
||||
responseChan <- APIResponse{
|
||||
SourceId: req.ServiceId,
|
||||
Resp: []byte(westResp),
|
||||
Resp: jsonResp,
|
||||
Success: success,
|
||||
}
|
||||
}(apiReq)
|
||||
|
Loading…
Reference in New Issue
Block a user