google: update error return format.

Change-Id: Id2cd28484e3724eee98757c2f40cbb237dee2c75
This commit is contained in:
Patrick Jones 2020-11-10 13:12:37 -08:00
parent 5908a54aa5
commit 57d1f928e5
1 changed files with 6 additions and 8 deletions

View File

@ -29,8 +29,7 @@ func ExchangeToken(ctx context.Context, endpoint string, request *STSTokenExchan
data.Set("scope", strings.Join(request.Scope, " ")) data.Set("scope", strings.Join(request.Scope, " "))
opts, err := json.Marshal(options) opts, err := json.Marshal(options)
if err != nil { if err != nil {
fmt.Errorf("oauth2/google: failed to marshal additional options: %v", err) return nil, fmt.Errorf("oauth2/google: failed to marshal additional options: %v", err)
return nil, err
} }
data.Set("options", string(opts)) data.Set("options", string(opts))
@ -39,8 +38,8 @@ func ExchangeToken(ctx context.Context, endpoint string, request *STSTokenExchan
req, err := http.NewRequestWithContext(ctx, "POST", endpoint, strings.NewReader(encodedData)) req, err := http.NewRequestWithContext(ctx, "POST", endpoint, strings.NewReader(encodedData))
if err != nil { if err != nil {
fmt.Errorf("oauth2/google: failed to properly build http request: %v", err) return nil, fmt.Errorf("oauth2/google: failed to properly build http request: %v", err)
return nil, err
} }
for key, list := range headers { for key, list := range headers {
for _, val := range list { for _, val := range list {
@ -52,8 +51,7 @@ func ExchangeToken(ctx context.Context, endpoint string, request *STSTokenExchan
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
fmt.Errorf("oauth2/google: invalid response from Secure Token Server: %v", err) return nil, fmt.Errorf("oauth2/google: invalid response from Secure Token Server: %v", err)
return nil, err
} }
defer resp.Body.Close() defer resp.Body.Close()
@ -62,8 +60,8 @@ func ExchangeToken(ctx context.Context, endpoint string, request *STSTokenExchan
for bodyJson.More() { for bodyJson.More() {
err = bodyJson.Decode(&stsResp) err = bodyJson.Decode(&stsResp)
if err != nil { if err != nil {
fmt.Errorf("oauth2/google: failed to unmarshal response body from Secure Token Server: %v", err) return nil, fmt.Errorf("oauth2/google: failed to unmarshal response body from Secure Token Server: %v", err)
return nil, err
} }
} }