Skip to content

Commit c391ce5

Browse files
committed
Merge pull request #9 from deet/master
Return HTTP response even on non-2XX responses. Clients might want it.
2 parents f12d198 + 2fe9298 commit c391ce5

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

oauth.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,8 @@ func (c *Consumer) httpExecute(
561561
// StatusMultipleChoices is 300, any 2xx response should be treated as success
562562
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {
563563
bytes, _ := ioutil.ReadAll(resp.Body)
564-
resp.Body.Close()
565564

566-
return nil, errors.New("HTTP response is not 200/OK as expected. Actual response: \n" +
565+
return resp, errors.New("HTTP response is not 200/OK as expected. Actual response: \n" +
567566
"\tResponse Status: '" + resp.Status + "'\n" +
568567
"\tResponse Code: " + strconv.Itoa(resp.StatusCode) + "\n" +
569568
"\tResponse Body: " + string(bytes) + "\n" +

oauth_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,13 @@ func Test404OnGet(t *testing.T) {
243243
m.httpClient.ReturnStatusCode(404, "Not Found")
244244

245245
atoken := &AccessToken{Token: "ATOKEN", Secret: "ASECRET"}
246-
_, err := c.Get("URL", map[string]string{}, atoken)
246+
resp, err := c.Get("URL", map[string]string{}, atoken)
247247
if err == nil {
248248
t.Fatal("Should have raised an error")
249249
}
250+
251+
assertEqM(t, 404, resp.StatusCode, "Response status code should equal the status code from HTTP response")
252+
250253
}
251254

252255
func TestMissingRequestTokenSecret(t *testing.T) {

0 commit comments

Comments
 (0)