From 79d460f156652724f6b78f96f8ac3d7bf9f5b160 Mon Sep 17 00:00:00 2001 From: Pierre G Date: Thu, 23 Jan 2025 13:50:29 +0100 Subject: [PATCH] fix: crash when running admin cluster deploy command (#416) --- pkg/auth_service.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/auth_service.go b/pkg/auth_service.go index 0c8405f8..813daf71 100644 --- a/pkg/auth_service.go +++ b/pkg/auth_service.go @@ -261,7 +261,15 @@ type QoveryClientApiRequest[T any] func(needToRefetchClient bool) (*T, *http.Res // RetryQoveryClientApiRequestOnUnauthorized To be able to ask for re-auth when first attempt leads to unauthorized func RetryQoveryClientApiRequestOnUnauthorized[T any](request QoveryClientApiRequest[T]) (*T, *http.Response, error) { qoveryStruct, response, err := request(false) - if response.StatusCode == 401 { + if err != nil { + return qoveryStruct, response, fmt.Errorf("RetryQoveryClientApiRequestOnUnauthorized: initial request error: %w", err) + } + + if response == nil { + return qoveryStruct, nil, fmt.Errorf("received nil response from request") + } + + if response.StatusCode == http.StatusUnauthorized { utils.Println("Needs to re-authenticate as the response is UNAUTHORIZED (401)") DoRequestUserToAuthenticate(false) qoveryStruct, response, err = request(true)