f
This commit is contained in:
@@ -160,7 +160,7 @@ func (s *ShumaiService) CallAPIForm(ctx context.Context, apiPath string, reqForm
|
||||
if err != nil {
|
||||
err = errors.Join(ErrSystem, err)
|
||||
if s.logger != nil {
|
||||
s.logger.LogError(requestID, transactionID, apiPath, err, reqFormData)
|
||||
s.logger.LogError(requestID, transactionID, apiPath, err, nil)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -188,7 +188,7 @@ func (s *ShumaiService) CallAPIForm(ctx context.Context, apiPath string, reqForm
|
||||
err = errors.Join(ErrSystem, err)
|
||||
}
|
||||
if s.logger != nil {
|
||||
s.logger.LogError(requestID, transactionID, apiPath, err, reqFormData)
|
||||
s.logger.LogError(requestID, transactionID, apiPath, err, nil)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -199,7 +199,7 @@ func (s *ShumaiService) CallAPIForm(ctx context.Context, apiPath string, reqForm
|
||||
if err != nil {
|
||||
err = errors.Join(ErrSystem, err)
|
||||
if s.logger != nil {
|
||||
s.logger.LogError(requestID, transactionID, apiPath, err, reqFormData)
|
||||
s.logger.LogError(requestID, transactionID, apiPath, err, nil)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -207,7 +207,21 @@ func (s *ShumaiService) CallAPIForm(ctx context.Context, apiPath string, reqForm
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
err = errors.Join(ErrDatasource, fmt.Errorf("HTTP %d", resp.StatusCode))
|
||||
if s.logger != nil {
|
||||
s.logger.LogError(requestID, transactionID, apiPath, err, reqFormData)
|
||||
var errorResponse interface{} = string(raw)
|
||||
// 尝试解析 JSON 获取 msg
|
||||
var tempResp ShumaiResponse
|
||||
if json.Unmarshal(raw, &tempResp) == nil {
|
||||
msg := tempResp.Msg
|
||||
if msg == "" {
|
||||
msg = tempResp.Message
|
||||
}
|
||||
if msg != "" {
|
||||
errorResponse = map[string]interface{}{
|
||||
"msg": msg,
|
||||
}
|
||||
}
|
||||
}
|
||||
s.logger.LogError(requestID, transactionID, apiPath, err, errorResponse)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -220,7 +234,7 @@ func (s *ShumaiService) CallAPIForm(ctx context.Context, apiPath string, reqForm
|
||||
if err := json.Unmarshal(raw, &shumaiResp); err != nil {
|
||||
err = errors.Join(ErrSystem, fmt.Errorf("响应解析失败: %w", err))
|
||||
if s.logger != nil {
|
||||
s.logger.LogError(requestID, transactionID, apiPath, err, reqFormData)
|
||||
s.logger.LogError(requestID, transactionID, apiPath, err, string(raw))
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -237,7 +251,10 @@ func (s *ShumaiService) CallAPIForm(ctx context.Context, apiPath string, reqForm
|
||||
shumaiErr = NewShumaiError(codeStr, msg)
|
||||
}
|
||||
if s.logger != nil {
|
||||
s.logger.LogError(requestID, transactionID, apiPath, shumaiErr, reqFormData)
|
||||
errorResponse := map[string]interface{}{
|
||||
"msg": msg,
|
||||
}
|
||||
s.logger.LogError(requestID, transactionID, apiPath, shumaiErr, errorResponse)
|
||||
}
|
||||
if shumaiErr.IsNoRecord() {
|
||||
return nil, errors.Join(ErrNotFound, shumaiErr)
|
||||
@@ -253,7 +270,10 @@ func (s *ShumaiService) CallAPIForm(ctx context.Context, apiPath string, reqForm
|
||||
if err != nil {
|
||||
err = errors.Join(ErrSystem, fmt.Errorf("data 序列化失败: %w", err))
|
||||
if s.logger != nil {
|
||||
s.logger.LogError(requestID, transactionID, apiPath, err, reqFormData)
|
||||
errorResponse := map[string]interface{}{
|
||||
"msg": msg,
|
||||
}
|
||||
s.logger.LogError(requestID, transactionID, apiPath, err, errorResponse)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user