@@ -17,14 +17,24 @@ import (
1717
1818// APIError represents an api error response.
1919type APIError struct {
20- StatusCode int `json:"status_code"` // HTTP status code
21- Method string `json:"method"` // HTTP method used for the request
22- URL string `json:"url"` // The URL of the HTTP request
20+ StatusCode int `json:"status_code"` // HTTP status code
21+ Method string `json:"method"` // HTTP method used for the request
22+ URL string `json:"url"` // The URL of the HTTP request
23+ HTTPStatus int `json:"httpStatus,omitempty"`
24+ Errors []Errors `json:"errors,omitempty"`
2325 Message string `json:"message"` // Summary of the error
2426 Details []string `json:"details,omitempty"` // Detailed error messages, if any
2527 RawResponse string `json:"raw_response"` // Raw response body for debugging
2628}
2729
30+ // Errors represents individual error details within an API error response.
31+ type Errors struct {
32+ Code string `json:"code,omitempty"`
33+ Field string `json:"field,omitempty"`
34+ Description string `json:"description,omitempty"`
35+ ID * string `json:"id,omitempty"`
36+ }
37+
2838// Error returns a string representation of the APIError, making it compatible with the error interface.
2939func (e * APIError ) Error () string {
3040 data , err := json .Marshal (e )
@@ -74,15 +84,14 @@ func HandleAPIErrorResponse(resp *http.Response, sugar *zap.SugaredLogger) *APIE
7484
7585// parseJSONResponse attempts to parse the JSON error response and update the APIError structure.
7686func parseJSONResponse (bodyBytes []byte , apiError * APIError ) {
77- apiError .RawResponse = string (bodyBytes )
78-
7987 if err := json .Unmarshal (bodyBytes , apiError ); err != nil {
88+ apiError .RawResponse = string (bodyBytes )
8089 } else {
8190 if apiError .Message == "" {
8291 apiError .Message = "An unknown error occurred"
8392 }
84- }
8593
94+ }
8695}
8796
8897// parseXMLResponse dynamically parses XML error responses and accumulates potential error messages.
0 commit comments