Add more explicit error handling around the OAuth flow
This commit is contained in:
parent
83c647366b
commit
635d2963f6
1 changed files with 10 additions and 1 deletions
|
|
@ -2,6 +2,7 @@ package auth
|
|||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
|
@ -81,8 +82,13 @@ func (oa *OAuthFlow) ObtainAccessToken() (accessToken string, err error) {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
err = fmt.Errorf("HTTP %d error while obtaining OAuth access token", resp.StatusCode)
|
||||
return
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
@ -92,6 +98,9 @@ func (oa *OAuthFlow) ObtainAccessToken() (accessToken string, err error) {
|
|||
return
|
||||
}
|
||||
accessToken = tokenValues.Get("access_token")
|
||||
if accessToken == "" {
|
||||
err = errors.New("the access token could not be read from HTTP response")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue