From 2e27b6b6cbfae950c7efb89687eb9f7976c2db17 Mon Sep 17 00:00:00 2001 From: Burcu Dogan Date: Thu, 23 Oct 2014 10:06:00 -0700 Subject: [PATCH] Handle non-2xx for metadata server responses. --- google/google.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/google/google.go b/google/google.go index b98ce81..2fcf8a6 100644 --- a/google/google.go +++ b/google/google.go @@ -15,6 +15,7 @@ package google import ( "encoding/json" + "fmt" "io/ioutil" "net/http" "time" @@ -114,6 +115,9 @@ func (c *ComputeEngineConfig) FetchToken(existing *oauth2.Token) (token *oauth2. return } defer resp.Body.Close() + if resp.StatusCode < 200 || resp.StatusCode > 299 { + return nil, fmt.Errorf("oauth2: can't retrieve a token from metadata server, status code: %d", resp.StatusCode) + } var tokenResp metaTokenRespBody err = json.NewDecoder(resp.Body).Decode(&tokenResp) if err != nil {