diff options
| author | Petter Rasmussen | 2016-02-16 21:22:30 +0100 |
|---|---|---|
| committer | Petter Rasmussen | 2016-02-16 21:22:30 +0100 |
| commit | a44ec784400bddfd489f86d77e72eb5ee06600fd (patch) | |
| tree | c8bad997d988c2894996001ff9e8269d4762a1d4 /auth | |
| parent | 3f8dc6312cc9b14897ff49439fb023e16e5f47d0 (diff) | |
| download | gdrive-a44ec784400bddfd489f86d77e72eb5ee06600fd.tar.bz2 | |
Error handling
Diffstat (limited to 'auth')
| -rw-r--r-- | auth/oauth.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/auth/oauth.go b/auth/oauth.go index b8f1d47..a9ab10e 100644 --- a/auth/oauth.go +++ b/auth/oauth.go @@ -1,6 +1,7 @@ package auth import ( + "fmt" "net/http" "golang.org/x/oauth2" ) @@ -22,7 +23,7 @@ func NewOauthClient(clientId, clientSecret, tokenFile string, authFn authCodeFn) // Read cached token token, exists, err := ReadToken(tokenFile) if err != nil { - return nil, err + return nil, fmt.Errorf("Failed to read token: %s", err) } // Require auth code if token file does not exist @@ -31,6 +32,9 @@ func NewOauthClient(clientId, clientSecret, tokenFile string, authFn authCodeFn) authUrl := conf.AuthCodeURL("state", oauth2.AccessTypeOffline) authCode := authFn(authUrl)() token, err = conf.Exchange(oauth2.NoContext, authCode) + if err != nil { + return nil, fmt.Errorf("Failed to exchange auth code for token: %s", err) + } } return oauth2.NewClient( |
