Fix responses logging without any content

This commit is contained in:
VnPower
2024-10-02 19:31:59 +07:00
parent ca0750ef88
commit bbf77baec3
+9 -6
View File
@@ -67,17 +67,25 @@ func retryRequest(ctx context.Context, reqFunc func(context.Context, string) (*r
return nil, err
}
start := time.Now()
resp, err := retryClient.Do(req)
end := time.Now()
// Unwrap the body here so that we could log stuff correctly
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
audit.LogAPIRoundTrip(audit.APIRequestSpan{
RequestId: request_context.GetFromContext(ctx).RequestId,
Response: resp,
Error: err,
Method: req.Method,
Token: tokenValue,
Body: "",
Body: string(body),
StartTime: start,
EndTime: end,
})
@@ -86,11 +94,6 @@ func retryRequest(ctx context.Context, reqFunc func(context.Context, string) (*r
if userToken == "" && !isPost {
tokenManager.MarkTokenStatus(token, token_manager.Good)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return &SimpleHTTPResponse{
StatusCode: resp.StatusCode,
Body: string(body),