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

Return HTTP response even on non-2XX responses. Clients might want it. #9

Merged
merged 1 commit into from
Sep 4, 2013
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
3 changes: 1 addition & 2 deletions oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,8 @@ func (c *Consumer) httpExecute(
// StatusMultipleChoices is 300, any 2xx response should be treated as success
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {
bytes, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()

return nil, errors.New("HTTP response is not 200/OK as expected. Actual response: \n" +
return resp, errors.New("HTTP response is not 200/OK as expected. Actual response: \n" +
"\tResponse Status: '" + resp.Status + "'\n" +
"\tResponse Code: " + strconv.Itoa(resp.StatusCode) + "\n" +
"\tResponse Body: " + string(bytes) + "\n" +
Expand Down
5 changes: 4 additions & 1 deletion oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,13 @@ func Test404OnGet(t *testing.T) {
m.httpClient.ReturnStatusCode(404, "Not Found")

atoken := &AccessToken{Token: "ATOKEN", Secret: "ASECRET"}
_, err := c.Get("URL", map[string]string{}, atoken)
resp, err := c.Get("URL", map[string]string{}, atoken)
if err == nil {
t.Fatal("Should have raised an error")
}

assertEqM(t, 404, resp.StatusCode, "Response status code should equal the status code from HTTP response")

}

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