Skip to content
This repository was archived by the owner on Jan 29, 2026. It is now read-only.

Commit 3a5d051

Browse files
committed
Wrap ErrNonHttp20xResponse error for better contextual messages
Signed-off-by: Andy Lo-A-Foe <andy.loafoe@gmail.com>
1 parent 1c98161 commit 3a5d051

File tree

5 files changed

+7
-8
lines changed

5 files changed

+7
-8
lines changed

audit/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,5 +219,5 @@ func checkResponse(r *http.Response) error {
219219
case 400:
220220
return ErrBadRequest
221221
}
222-
return ErrNonHttp20xResponse
222+
return fmt.Errorf("%s %s: StatusCode %d: %w", r.Request.Method, r.Request.RequestURI, r.StatusCode, ErrNonHttp20xResponse)
223223
}

cartel/client.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,10 @@ func (c *Client) do(req *http.Request, v interface{}) (*Response, error) {
157157
}
158158
req.Close = true // Always close request
159159
resp, err := c.httpClient.Do(req)
160-
if err != nil && err != io.EOF {
160+
if resp == nil || (err != nil && err != io.EOF) {
161161
return nil, fmt.Errorf("client.do: %w", err)
162162
}
163163
defer resp.Body.Close()
164-
165164
response := newResponse(resp)
166165

167166
if c.debugFile != nil {
@@ -192,7 +191,7 @@ func checkResponse(r *http.Response) error {
192191
case 200, 201, 202, 204, 304:
193192
return nil
194193
}
195-
return ErrNonHttp20xResponse
194+
return fmt.Errorf("%s %s: StatusCode %d: %w", r.Request.Method, r.Request.RequestURI, r.StatusCode, ErrNonHttp20xResponse)
196195
}
197196

198197
// newRequest creates an API request. A relative URL path can be provided in

cdr/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,5 +259,5 @@ func checkResponse(r *http.Response) error {
259259
case 200, 201, 202, 204, 304:
260260
return nil
261261
}
262-
return ErrNonHttp20xResponse
262+
return fmt.Errorf("%s %s: StatusCode %d: %w", r.Request.Method, r.Request.RequestURI, r.StatusCode, ErrNonHttp20xResponse)
263263
}

console/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,5 +430,5 @@ func checkResponse(r *http.Response) error {
430430
case 200, 201, 202, 204, 304:
431431
return nil
432432
}
433-
return ErrNonHttp20xResponse
433+
return fmt.Errorf("%s %s: StatusCode %d: %w", r.Request.Method, r.Request.RequestURI, r.StatusCode, ErrNonHttp20xResponse)
434434
}

dicom/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ func checkResponse(r *http.Response) error {
271271
case 200, 201, 202, 204, 304:
272272
return nil
273273
case 403:
274-
return ErrDICOMForbidden
274+
return fmt.Errorf("%s %s: StatusCode %d: %w", r.Request.Method, r.Request.RequestURI, r.StatusCode, ErrDICOMForbidden)
275275
}
276-
return ErrNonHttp20xResponse
276+
return fmt.Errorf("%s %s: StatusCode %d: %w", r.Request.Method, r.Request.RequestURI, r.StatusCode, ErrNonHttp20xResponse)
277277
}

0 commit comments

Comments
 (0)