aboutsummaryrefslogtreecommitdiffstats
path: root/auth
diff options
context:
space:
mode:
authorPetter Rasmussen2016-02-16 21:22:30 +0100
committerPetter Rasmussen2016-02-16 21:22:30 +0100
commita44ec784400bddfd489f86d77e72eb5ee06600fd (patch)
treec8bad997d988c2894996001ff9e8269d4762a1d4 /auth
parent3f8dc6312cc9b14897ff49439fb023e16e5f47d0 (diff)
downloadgdrive-a44ec784400bddfd489f86d77e72eb5ee06600fd.tar.bz2
Error handling
Diffstat (limited to 'auth')
-rw-r--r--auth/oauth.go6
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(