Skip to content

Commit

Permalink
fix: fix error handling when retrying cluster update commands
Browse files Browse the repository at this point in the history
  • Loading branch information
fabienfleureau committed Feb 11, 2025
1 parent 47754b5 commit b454bd9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pkg/admin_cluster_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func (service AdminClusterBatchDeployServiceImpl) Deploy(clusters []ClusterDetai
}
return qoveryClient.ClustersAPI.GetClusterStatus(context.Background(), cluster.OrganizationId, cluster.ClusterId).Execute()
})
if response.StatusCode > 200 || err != nil {
if response == nil || response.StatusCode > 200 || err != nil {
return nil, err
}

Expand Down Expand Up @@ -416,7 +416,7 @@ func (service AdminClusterBatchDeployServiceImpl) Deploy(clusters []ClusterDetai
}
return qoveryClient.ClustersAPI.GetClusterStatus(context.Background(), cluster.OrganizationId, cluster.ClusterId).Execute()
})
if response.StatusCode > 200 || err != nil {
if response == nil || response.StatusCode > 200 || err != nil {
return nil, err
}

Expand Down
10 changes: 1 addition & 9 deletions pkg/auth_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,7 @@ 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 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 {
if response != nil && response.StatusCode == http.StatusUnauthorized {
utils.Println("Needs to re-authenticate as the response is UNAUTHORIZED (401)")
DoRequestUserToAuthenticate(false)
qoveryStruct, response, err = request(true)
Expand Down

0 comments on commit b454bd9

Please sign in to comment.