diff --git a/pkg/auth_service.go b/pkg/auth_service.go index 0c8405f..813daf7 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)