Skip to content

Commit

Permalink
Merge pull request #9 from deet/master
Browse files Browse the repository at this point in the history
Return HTTP response even on non-2XX responses. Clients might want it.
  • Loading branch information
mrjones committed Sep 4, 2013
2 parents f12d198 + 2fe9298 commit c391ce5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
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

0 comments on commit c391ce5

Please sign in to comment.