diff options
author | Eirik Nygaard <eirik.nygaard@yahooinc.com> | 2022-03-31 15:25:59 +0200 |
---|---|---|
committer | Eirik Nygaard <eirik.nygaard@yahooinc.com> | 2022-03-31 15:25:59 +0200 |
commit | 502c8072d1f7ccdc45d7db9d1bb3848b822bfc21 (patch) | |
tree | 60020926fd605e2163a959ffb6aac026111e956f /client | |
parent | 211fdb61ecf7379c8113e0da413a8cc16f72494d (diff) |
Parse json error response and only print the description from it
Diffstat (limited to 'client')
-rw-r--r-- | client/go/auth/token.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/client/go/auth/token.go b/client/go/auth/token.go index b7bf5d76042..d6f5e6dfa43 100644 --- a/client/go/auth/token.go +++ b/client/go/auth/token.go @@ -10,6 +10,7 @@ import ( "io" "net/http" "net/url" + "strings" ) type TokenResponse struct { @@ -54,8 +55,13 @@ func (t *TokenRetriever) Refresh(ctx context.Context, system string) (TokenRespo defer r.Body.Close() if r.StatusCode != http.StatusOK { b, _ := io.ReadAll(r.Body) - bodyStr := string(b) - return TokenResponse{}, fmt.Errorf("cannot get a new access token from the refresh token: %s", bodyStr) + res := struct { + Description string `json:"error_description"` + }{} + if json.Unmarshal(b, &res) == nil { + return TokenResponse{}, errors.New(strings.ToLower(strings.TrimSuffix(res.Description, "."))) + } + return TokenResponse{}, fmt.Errorf("cannot get a new access token from the refresh token: %s", string(b)) } var res TokenResponse |