Skip to content

Commit

Permalink
All non-200 status code from MDS should raise error (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaitanyaKulkarni28 authored Mar 20, 2024
1 parent 17acf80 commit 1ecade1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,15 @@ func (c *Client) do(ctx context.Context, cfg requestConfig) (*http.Response, err
return resp, fmt.Errorf("error connecting to metadata server: %+v", err)
}

statusCodeMsg := "error connecting to metadata server, status code: %d"
switch resp.StatusCode {
case 404, 412:
return resp, fmt.Errorf(statusCodeMsg, resp.StatusCode)
if resp == nil {
return nil, fmt.Errorf("got nil response from metadata server")
}

if resp.StatusCode != http.StatusOK {
defer resp.Body.Close()
// Ignore read error as we are returning original error and wrapping MDS error code.
r, _ := io.ReadAll(resp.Body)
return resp, fmt.Errorf("invalid response from metadata server, status code: %d, reason: %s", resp.StatusCode, string(r))
}

if cfg.hang {
Expand Down

0 comments on commit 1ecade1

Please sign in to comment.