Skip to content

Commit 3015325

Browse files
authored
Merge pull request #294 from neilmartin83/nm-json-error-response-2025-07-31
fix: store raw response in APIError during JSON parsing
2 parents 4011b93 + b706b68 commit 3015325

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

response/error.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,24 @@ import (
1717

1818
// APIError represents an api error response.
1919
type 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.
2939
func (e *APIError) Error() string {
3040
data, err := json.Marshal(e)

0 commit comments

Comments
 (0)