Skip to content

Commit 1ecade1

Browse files
All non-200 status code from MDS should raise error (#383)
1 parent 17acf80 commit 1ecade1

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

metadata/metadata.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,15 @@ func (c *Client) do(ctx context.Context, cfg requestConfig) (*http.Response, err
506506
return resp, fmt.Errorf("error connecting to metadata server: %+v", err)
507507
}
508508

509-
statusCodeMsg := "error connecting to metadata server, status code: %d"
510-
switch resp.StatusCode {
511-
case 404, 412:
512-
return resp, fmt.Errorf(statusCodeMsg, resp.StatusCode)
509+
if resp == nil {
510+
return nil, fmt.Errorf("got nil response from metadata server")
511+
}
512+
513+
if resp.StatusCode != http.StatusOK {
514+
defer resp.Body.Close()
515+
// Ignore read error as we are returning original error and wrapping MDS error code.
516+
r, _ := io.ReadAll(resp.Body)
517+
return resp, fmt.Errorf("invalid response from metadata server, status code: %d, reason: %s", resp.StatusCode, string(r))
513518
}
514519

515520
if cfg.hang {

0 commit comments

Comments
 (0)