Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(googleapi): fill response headers in Error #1418

Merged
merged 2 commits into from Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions googleapi/googleapi.go
Expand Up @@ -141,6 +141,7 @@ func CheckResponse(res *http.Response) error {
jerr.Error.Code = res.StatusCode
}
jerr.Error.Body = string(slurp)
jerr.Error.Header = res.Header
return jerr.Error
}
}
Expand Down
14 changes: 14 additions & 0 deletions googleapi/googleapi_test.go
Expand Up @@ -298,6 +298,20 @@ Details:
}
]`,
},
{
// Case: Confirm that response headers are propagated to the error.
&http.Response{
StatusCode: http.StatusInternalServerError,
Header: map[string][]string{"key1": {"value1"}, "key2": {"value2", "value3"}},
},
`{"error":{}}`,
&Error{
Code: http.StatusInternalServerError,
Body: `{"error":{}}`,
Header: map[string][]string{"key1": {"value1"}, "key2": {"value2", "value3"}},
},
`googleapi: got HTTP response code 500 with body: {"error":{}}`,
},
}

func TestCheckResponse(t *testing.T) {
Expand Down