Skip to content

Commit

Permalink
Error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
prasmussen committed Feb 16, 2016
1 parent 3f8dc63 commit a44ec78
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion auth/oauth.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package auth

import (
"fmt"
"net/http"
"golang.org/x/oauth2"
)
Expand All @@ -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
Expand All @@ -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(
Expand Down

0 comments on commit a44ec78

Please sign in to comment.