Skip to content

Commit a425cc8

Browse files
committed
fix: store raw response in APIError during JSON parsing
1 parent 4011b93 commit a425cc8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

response/error.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,15 @@ func HandleAPIErrorResponse(resp *http.Response, sugar *zap.SugaredLogger) *APIE
7474

7575
// parseJSONResponse attempts to parse the JSON error response and update the APIError structure.
7676
func parseJSONResponse(bodyBytes []byte, apiError *APIError) {
77+
apiError.RawResponse = string(bodyBytes)
78+
7779
if err := json.Unmarshal(bodyBytes, apiError); err != nil {
78-
apiError.RawResponse = string(bodyBytes)
7980
} else {
8081
if apiError.Message == "" {
8182
apiError.Message = "An unknown error occurred"
8283
}
83-
8484
}
85+
8586
}
8687

8788
// parseXMLResponse dynamically parses XML error responses and accumulates potential error messages.

0 commit comments

Comments
 (0)