File tree Expand file tree Collapse file tree 1 file changed +25
-3
lines changed
Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -83,10 +83,32 @@ func (e Errors) Error() string {
8383 return strings .Join (msgs , ", " )
8484}
8585
86- // HandleError makes an error from http.Response.
87- // It is the caller's responsibility to close resp.Body.
86+ type APIError struct {
87+ Status string
88+ StatusCode int
89+ inner error
90+ }
91+
92+ func (e APIError ) Error () string {
93+ return fmt .Sprintf ("%s: %s" , e .Status , e .inner )
94+ }
95+
96+ func (e APIError ) Unwrap () error {
97+ return e .inner
98+ }
99+
100+ func NewAPIError (status string , code int , inner error ) error {
101+ return APIError {
102+ Status : status ,
103+ StatusCode : code ,
104+ inner : inner ,
105+ }
106+ }
107+
108+ // HandleError makes an error from http.Response. It is the caller's
109+ // responsibility to close resp.Body.
88110func HandleError (resp * http.Response ) error {
89- return fmt . Errorf ( "%s: %w" , resp .Status , newErrorFromBody (resp ))
111+ return NewAPIError ( resp . Status , resp .StatusCode , newErrorFromBody (resp ))
90112}
91113
92114func newErrorFromBody (resp * http.Response ) error {
You can’t perform that action at this time.
0 commit comments