summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorEirik Nygaard <eirik.nygaard@yahooinc.com>2022-03-31 15:29:30 +0200
committerGitHub <noreply@github.com>2022-03-31 15:29:30 +0200
commit47e4ac1d21570b8d8665e2d9a142871d7ea2442b (patch)
tree3006cc113e69b44c53e34cb107a391b4db13f7b0 /client
parentd0fa48f2559c297e7b9c15137f3c04bc32fc65fa (diff)
parent502c8072d1f7ccdc45d7db9d1bb3848b822bfc21 (diff)
Merge pull request #21921 from vespa-engine/ean/vespa-cli-auth0-error-message-improvement
Parse json error response and only print the description from it
Diffstat (limited to 'client')
-rw-r--r--client/go/auth/token.go10
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