Skip to content

Commit

Permalink
internal/client: add additional context to HTTP error message
Browse files Browse the repository at this point in the history
Add HTTP method and request URL to error message for unexpected
status code when accessing vulndb.

For golang/go#62603

Change-Id: I7789b6eb81d2d580a62a4d4f38c9d02667b6a365
Reviewed-on: https://go-review.googlesource.com/c/vuln/+/528215
Reviewed-by: Zvonimir Pavlinovic <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
tatianab committed Sep 13, 2023
1 parent b7c0c6e commit 800e121
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions internal/client/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ type httpSource struct {
func (hs *httpSource) get(ctx context.Context, endpoint string) (_ []byte, err error) {
derrors.Wrap(&err, "get(%s)", endpoint)

method := http.MethodGet
reqURL := fmt.Sprintf("%s/%s", hs.url, endpoint+".json.gz")
req, err := http.NewRequestWithContext(ctx, http.MethodGet, reqURL, nil)
req, err := http.NewRequestWithContext(ctx, method, reqURL, nil)
if err != nil {
return nil, err
}
Expand All @@ -56,7 +57,7 @@ func (hs *httpSource) get(ctx context.Context, endpoint string) (_ []byte, err e
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected HTTP status code: %d", resp.StatusCode)
return nil, fmt.Errorf("HTTP %s %s returned unexpected status: %s", method, reqURL, resp.Status)
}

// Uncompress the result.
Expand Down

0 comments on commit 800e121

Please sign in to comment.