From e805ac1d59977725547ed57ee3f166c2d41d4185 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Wed, 7 Feb 2024 11:00:06 -0800 Subject: [PATCH] fix response on token error --- server/auth.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/auth.go b/server/auth.go index 8faf1e4b..0d09668d 100644 --- a/server/auth.go +++ b/server/auth.go @@ -111,8 +111,14 @@ func getAuthToken(ctx context.Context, redirData AuthRedirect) (string, error) { defer resp.Body.Close() if resp.StatusCode >= http.StatusBadRequest { - body, _ := io.ReadAll(resp.Body) - return "", fmt.Errorf("on pull registry responded with code %d: %s", resp.StatusCode, body) + responseBody, err := io.ReadAll(resp.Body) + if err != nil { + return "", fmt.Errorf("%d: %v", resp.StatusCode, err) + } else if len(responseBody) > 0 { + return "", fmt.Errorf("%d: %s", resp.StatusCode, responseBody) + } + + return "", fmt.Errorf("%s", resp.Status) } respBody, err := io.ReadAll(resp.Body)