@@ -79,13 +79,15 @@ func (c *Config) RequestToken() (requestToken, requestSecret string, err error)
7979 }
8080 // when err is nil, resp contains a non-nil resp.Body which must be closed
8181 defer resp .Body .Close ()
82- if resp .StatusCode != http .StatusOK && resp .StatusCode != http .StatusCreated {
83- return "" , "" , fmt .Errorf ("oauth1: Server returned status %d" , resp .StatusCode )
84- }
82+
8583 body , err := ioutil .ReadAll (resp .Body )
8684 if err != nil {
87- return "" , "" , err
85+ return "" , "" , fmt . Errorf ( "oauth1: error reading Body: %v" , err )
8886 }
87+ if resp .StatusCode != http .StatusOK && resp .StatusCode != http .StatusCreated {
88+ return "" , "" , fmt .Errorf ("oauth1: invalid status %d: %s" , resp .StatusCode , body )
89+ }
90+
8991 // ParseQuery to decode URL-encoded application/x-www-form-urlencoded body
9092 values , err := url .ParseQuery (string (body ))
9193 if err != nil {
@@ -156,13 +158,15 @@ func (c *Config) AccessToken(requestToken, requestSecret, verifier string) (acce
156158 }
157159 // when err is nil, resp contains a non-nil resp.Body which must be closed
158160 defer resp .Body .Close ()
159- if resp .StatusCode != http .StatusOK && resp .StatusCode != http .StatusCreated {
160- return "" , "" , fmt .Errorf ("oauth1: Server returned status %d" , resp .StatusCode )
161- }
161+
162162 body , err := ioutil .ReadAll (resp .Body )
163163 if err != nil {
164- return "" , "" , err
164+ return "" , "" , fmt . Errorf ( "oauth1: error reading Body: %v" , err )
165165 }
166+ if resp .StatusCode != http .StatusOK && resp .StatusCode != http .StatusCreated {
167+ return "" , "" , fmt .Errorf ("oauth1: invalid status %d: %s" , resp .StatusCode , body )
168+ }
169+
166170 // ParseQuery to decode URL-encoded application/x-www-form-urlencoded body
167171 values , err := url .ParseQuery (string (body ))
168172 if err != nil {
0 commit comments