forked from Mirrors/oauth2
Handle non-2xx for metadata server responses.
This commit is contained in:
parent
4b407cace1
commit
2e27b6b6cb
|
@ -15,6 +15,7 @@ package google
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
@ -114,6 +115,9 @@ func (c *ComputeEngineConfig) FetchToken(existing *oauth2.Token) (token *oauth2.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
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
|
var tokenResp metaTokenRespBody
|
||||||
err = json.NewDecoder(resp.Body).Decode(&tokenResp)
|
err = json.NewDecoder(resp.Body).Decode(&tokenResp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue