Skip to content

Commit 274880c

Browse files
committed
Refactor Error() method to return JSON representation of APIError
1 parent 9923f37 commit 274880c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

httpclient/httpclient_error_response.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ type StructuredError struct {
3030
} `json:"error"`
3131
}
3232

33-
// Error returns a string representation of the APIError.
33+
// Error returns a JSON representation of the APIError.
3434
func (e *APIError) Error() string {
35-
return fmt.Sprintf("API Error (Type: %s, Code: %d): %s", e.Type, e.StatusCode, e.Message)
35+
data, err := json.Marshal(e)
36+
if err != nil {
37+
return fmt.Sprintf("Error encoding APIError to JSON: %s", err)
38+
}
39+
return string(data)
3640
}
3741

3842
// handleAPIErrorResponse attempts to parse the error response from the API and logs using the zap logger.

0 commit comments

Comments
 (0)