fix
This commit is contained in:
@@ -99,7 +99,7 @@ func (w *WestDexService) CallAPI(ctx context.Context, code string, reqData map[s
|
||||
|
||||
jsonData, marshalErr := json.Marshal(reqData)
|
||||
if marshalErr != nil {
|
||||
err = fmt.Errorf("%w: %s", ErrSystem, marshalErr.Error())
|
||||
err = errors.Join(ErrSystem, marshalErr)
|
||||
if w.logger != nil {
|
||||
w.logger.LogError(requestID, transactionID, code, err, reqData)
|
||||
}
|
||||
@@ -109,7 +109,7 @@ func (w *WestDexService) CallAPI(ctx context.Context, code string, reqData map[s
|
||||
// 创建HTTP POST请求
|
||||
req, newRequestErr := http.NewRequestWithContext(ctx, "POST", reqUrl, bytes.NewBuffer(jsonData))
|
||||
if newRequestErr != nil {
|
||||
err = fmt.Errorf("%w: %s", ErrSystem, newRequestErr.Error())
|
||||
err = errors.Join(ErrSystem, newRequestErr)
|
||||
if w.logger != nil {
|
||||
w.logger.LogError(requestID, transactionID, code, err, reqData)
|
||||
}
|
||||
@@ -123,7 +123,7 @@ func (w *WestDexService) CallAPI(ctx context.Context, code string, reqData map[s
|
||||
client := &http.Client{}
|
||||
httpResp, clientDoErr := client.Do(req)
|
||||
if clientDoErr != nil {
|
||||
err = fmt.Errorf("%w: %s", ErrSystem, clientDoErr.Error())
|
||||
err = errors.Join(ErrSystem, clientDoErr)
|
||||
if w.logger != nil {
|
||||
w.logger.LogError(requestID, transactionID, code, err, reqData)
|
||||
}
|
||||
@@ -134,7 +134,7 @@ func (w *WestDexService) CallAPI(ctx context.Context, code string, reqData map[s
|
||||
if closeErr != nil {
|
||||
// 记录关闭错误
|
||||
if w.logger != nil {
|
||||
w.logger.LogError(requestID, transactionID, code, fmt.Errorf("关闭响应体失败: %w", closeErr), reqData)
|
||||
w.logger.LogError(requestID, transactionID, code, errors.Join(ErrSystem, fmt.Errorf("关闭响应体失败: %w", closeErr)), reqData)
|
||||
}
|
||||
}
|
||||
}(httpResp.Body)
|
||||
@@ -147,7 +147,7 @@ func (w *WestDexService) CallAPI(ctx context.Context, code string, reqData map[s
|
||||
// 读取响应体
|
||||
bodyBytes, ReadErr := io.ReadAll(httpResp.Body)
|
||||
if ReadErr != nil {
|
||||
err = fmt.Errorf("%w: %s", ErrSystem, ReadErr.Error())
|
||||
err = errors.Join(ErrSystem, ReadErr)
|
||||
if w.logger != nil {
|
||||
w.logger.LogError(requestID, transactionID, code, err, reqData)
|
||||
}
|
||||
@@ -158,7 +158,7 @@ func (w *WestDexService) CallAPI(ctx context.Context, code string, reqData map[s
|
||||
var westDexResp WestResp
|
||||
UnmarshalErr := json.Unmarshal(bodyBytes, &westDexResp)
|
||||
if UnmarshalErr != nil {
|
||||
err = UnmarshalErr
|
||||
err = errors.Join(ErrSystem, UnmarshalErr)
|
||||
if w.logger != nil {
|
||||
w.logger.LogError(requestID, transactionID, code, err, reqData)
|
||||
}
|
||||
@@ -172,7 +172,7 @@ func (w *WestDexService) CallAPI(ctx context.Context, code string, reqData map[s
|
||||
|
||||
if westDexResp.Code != "00000" && westDexResp.Code != "200" && westDexResp.Code != "0" {
|
||||
if westDexResp.Data == "" {
|
||||
err = fmt.Errorf("%w: %s", ErrSystem, westDexResp.Message)
|
||||
err = errors.Join(ErrSystem, fmt.Errorf(westDexResp.Message))
|
||||
if w.logger != nil {
|
||||
w.logger.LogErrorWithResponseID(requestID, transactionID, code, err, reqData, westDexResp.ID)
|
||||
}
|
||||
@@ -180,7 +180,7 @@ func (w *WestDexService) CallAPI(ctx context.Context, code string, reqData map[s
|
||||
}
|
||||
decryptedData, DecryptErr := crypto.WestDexDecrypt(westDexResp.Data, w.config.Key)
|
||||
if DecryptErr != nil {
|
||||
err = fmt.Errorf("%w: %s", ErrSystem, DecryptErr.Error())
|
||||
err = errors.Join(ErrSystem, DecryptErr)
|
||||
if w.logger != nil {
|
||||
w.logger.LogErrorWithResponseID(requestID, transactionID, code, err, reqData, westDexResp.ID)
|
||||
}
|
||||
@@ -189,17 +189,17 @@ func (w *WestDexService) CallAPI(ctx context.Context, code string, reqData map[s
|
||||
|
||||
// 记录业务错误日志,包含响应ID
|
||||
if w.logger != nil {
|
||||
w.logger.LogErrorWithResponseID(requestID, transactionID, code, fmt.Errorf("%w: %s", ErrDatasource, westDexResp.Message), reqData, westDexResp.ID)
|
||||
w.logger.LogErrorWithResponseID(requestID, transactionID, code, errors.Join(ErrDatasource, fmt.Errorf(westDexResp.Message)), reqData, westDexResp.ID)
|
||||
}
|
||||
|
||||
// 记录性能日志(失败)
|
||||
// 注意:通用日志系统不包含性能日志功能
|
||||
|
||||
return decryptedData, fmt.Errorf("%w: %s", ErrDatasource, westDexResp.Message)
|
||||
return decryptedData, errors.Join(ErrDatasource, fmt.Errorf(westDexResp.Message))
|
||||
}
|
||||
|
||||
if westDexResp.Data == "" {
|
||||
err = fmt.Errorf("%w: %s", ErrSystem, westDexResp.Message)
|
||||
err = errors.Join(ErrSystem, fmt.Errorf(westDexResp.Message))
|
||||
if w.logger != nil {
|
||||
w.logger.LogErrorWithResponseID(requestID, transactionID, code, err, reqData, westDexResp.ID)
|
||||
}
|
||||
@@ -208,7 +208,7 @@ func (w *WestDexService) CallAPI(ctx context.Context, code string, reqData map[s
|
||||
|
||||
decryptedData, DecryptErr := crypto.WestDexDecrypt(westDexResp.Data, w.config.Key)
|
||||
if DecryptErr != nil {
|
||||
err = fmt.Errorf("%w: %s", ErrSystem, DecryptErr.Error())
|
||||
err = errors.Join(ErrSystem, DecryptErr)
|
||||
if w.logger != nil {
|
||||
w.logger.LogErrorWithResponseID(requestID, transactionID, code, err, reqData, westDexResp.ID)
|
||||
}
|
||||
@@ -222,7 +222,7 @@ func (w *WestDexService) CallAPI(ctx context.Context, code string, reqData map[s
|
||||
}
|
||||
|
||||
// 记录HTTP错误
|
||||
err = fmt.Errorf("%w: 西部请求失败Code: %d", ErrSystem, httpResp.StatusCode)
|
||||
err = errors.Join(ErrSystem, fmt.Errorf("西部请求失败Code: %d", httpResp.StatusCode))
|
||||
if w.logger != nil {
|
||||
w.logger.LogError(requestID, transactionID, code, err, reqData)
|
||||
// 注意:通用日志系统不包含性能日志功能
|
||||
@@ -252,7 +252,7 @@ func (w *WestDexService) G05HZ01CallAPI(ctx context.Context, code string, reqDat
|
||||
|
||||
jsonData, marshalErr := json.Marshal(reqData)
|
||||
if marshalErr != nil {
|
||||
err = fmt.Errorf("%w: %s", ErrSystem, marshalErr.Error())
|
||||
err = errors.Join(ErrSystem, marshalErr)
|
||||
if w.logger != nil {
|
||||
w.logger.LogError(requestID, transactionID, code, err, reqData)
|
||||
}
|
||||
@@ -262,7 +262,7 @@ func (w *WestDexService) G05HZ01CallAPI(ctx context.Context, code string, reqDat
|
||||
// 创建HTTP POST请求
|
||||
req, newRequestErr := http.NewRequestWithContext(ctx, "POST", reqUrl, bytes.NewBuffer(jsonData))
|
||||
if newRequestErr != nil {
|
||||
err = fmt.Errorf("%w: %s", ErrSystem, newRequestErr.Error())
|
||||
err = errors.Join(ErrSystem, newRequestErr)
|
||||
if w.logger != nil {
|
||||
w.logger.LogError(requestID, transactionID, code, err, reqData)
|
||||
}
|
||||
@@ -276,7 +276,7 @@ func (w *WestDexService) G05HZ01CallAPI(ctx context.Context, code string, reqDat
|
||||
client := &http.Client{}
|
||||
httpResp, clientDoErr := client.Do(req)
|
||||
if clientDoErr != nil {
|
||||
err = fmt.Errorf("%w: %s", ErrSystem, clientDoErr.Error())
|
||||
err = errors.Join(ErrSystem, clientDoErr)
|
||||
if w.logger != nil {
|
||||
w.logger.LogError(requestID, transactionID, code, err, reqData)
|
||||
}
|
||||
@@ -287,7 +287,7 @@ func (w *WestDexService) G05HZ01CallAPI(ctx context.Context, code string, reqDat
|
||||
if closeErr != nil {
|
||||
// 记录关闭错误
|
||||
if w.logger != nil {
|
||||
w.logger.LogError(requestID, transactionID, code, fmt.Errorf("关闭响应体失败: %w", closeErr), reqData)
|
||||
w.logger.LogError(requestID, transactionID, code, errors.Join(ErrSystem, fmt.Errorf("关闭响应体失败: %w", closeErr)), reqData)
|
||||
}
|
||||
}
|
||||
}(httpResp.Body)
|
||||
@@ -298,7 +298,7 @@ func (w *WestDexService) G05HZ01CallAPI(ctx context.Context, code string, reqDat
|
||||
if httpResp.StatusCode == 200 {
|
||||
bodyBytes, ReadErr := io.ReadAll(httpResp.Body)
|
||||
if ReadErr != nil {
|
||||
err = fmt.Errorf("%w: %s", ErrSystem, ReadErr.Error())
|
||||
err = errors.Join(ErrSystem, ReadErr)
|
||||
if w.logger != nil {
|
||||
w.logger.LogError(requestID, transactionID, code, err, reqData)
|
||||
}
|
||||
@@ -308,7 +308,7 @@ func (w *WestDexService) G05HZ01CallAPI(ctx context.Context, code string, reqDat
|
||||
var westDexResp G05HZ01WestResp
|
||||
UnmarshalErr := json.Unmarshal(bodyBytes, &westDexResp)
|
||||
if UnmarshalErr != nil {
|
||||
err = fmt.Errorf("%w: %s", ErrSystem, UnmarshalErr.Error())
|
||||
err = errors.Join(ErrSystem, UnmarshalErr)
|
||||
if w.logger != nil {
|
||||
w.logger.LogError(requestID, transactionID, code, err, reqData)
|
||||
}
|
||||
@@ -322,7 +322,7 @@ func (w *WestDexService) G05HZ01CallAPI(ctx context.Context, code string, reqDat
|
||||
|
||||
if westDexResp.Code != "0000" {
|
||||
if westDexResp.Data == nil {
|
||||
err = fmt.Errorf("%w: %s", ErrSystem, westDexResp.Message)
|
||||
err = errors.Join(ErrSystem, fmt.Errorf(westDexResp.Message))
|
||||
if w.logger != nil {
|
||||
w.logger.LogErrorWithResponseID(requestID, transactionID, code, err, reqData, westDexResp.ID)
|
||||
}
|
||||
@@ -330,18 +330,18 @@ func (w *WestDexService) G05HZ01CallAPI(ctx context.Context, code string, reqDat
|
||||
} else {
|
||||
// 记录业务错误日志,包含响应ID
|
||||
if w.logger != nil {
|
||||
w.logger.LogErrorWithResponseID(requestID, transactionID, code, fmt.Errorf("%w: %s", ErrSystem, string(westDexResp.Data)), reqData, westDexResp.ID)
|
||||
w.logger.LogErrorWithResponseID(requestID, transactionID, code, errors.Join(ErrSystem, fmt.Errorf(string(westDexResp.Data))), reqData, westDexResp.ID)
|
||||
}
|
||||
|
||||
// 记录性能日志(失败)
|
||||
// 注意:通用日志系统不包含性能日志功能
|
||||
|
||||
return westDexResp.Data, fmt.Errorf("%w: %s", ErrSystem, string(westDexResp.Data))
|
||||
return westDexResp.Data, errors.Join(ErrSystem, fmt.Errorf(string(westDexResp.Data)))
|
||||
}
|
||||
}
|
||||
|
||||
if westDexResp.Data == nil {
|
||||
err = fmt.Errorf("%w: %s", ErrSystem, westDexResp.Message)
|
||||
err = errors.Join(ErrSystem, fmt.Errorf(westDexResp.Message))
|
||||
if w.logger != nil {
|
||||
w.logger.LogErrorWithResponseID(requestID, transactionID, code, err, reqData, westDexResp.ID)
|
||||
}
|
||||
@@ -354,7 +354,7 @@ func (w *WestDexService) G05HZ01CallAPI(ctx context.Context, code string, reqDat
|
||||
return westDexResp.Data, nil
|
||||
} else {
|
||||
// 记录HTTP错误
|
||||
err = fmt.Errorf("%w: 西部请求失败Code: %d", ErrSystem, httpResp.StatusCode)
|
||||
err = errors.Join(ErrSystem, fmt.Errorf("西部请求失败Code: %d", httpResp.StatusCode))
|
||||
if w.logger != nil {
|
||||
w.logger.LogError(requestID, transactionID, code, err, reqData)
|
||||
// 注意:通用日志系统不包含性能日志功能
|
||||
|
||||
Reference in New Issue
Block a user