From b9d61bb261b80175b8e2dd839a0c0130a10ec269 Mon Sep 17 00:00:00 2001 From: Pierre Gerbelot Date: Thu, 23 Jan 2025 12:07:48 +0100 Subject: [PATCH] fix: crash when running admin cluster deploy command --- 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)