Skip to content

Commit 3a12fa1

Browse files
authored
Merge pull request #530 from nais/fix_api_error_handling
fix: handle google api error 403 without stopping the execution
2 parents 5d38c00 + 4425fe2 commit 3a12fa1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

pkg/kubeconfig/gcpcluster.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8-
"github.com/googleapis/gax-go/v2/apierror"
8+
"google.golang.org/api/googleapi"
9+
"net/http"
910
"strings"
1011

1112
"google.golang.org/api/compute/v1"
@@ -79,10 +80,9 @@ func getGCPClusters(ctx context.Context, project project, options filterOptions)
7980
call := svc.Projects.Locations.Clusters.List("projects/" + project.ID + "/locations/-")
8081
response, err := call.Do()
8182
if err != nil {
82-
if errors.Is(err, &apierror.APIError{}) {
83-
var apiErr *apierror.APIError
84-
errors.As(err, &apiErr)
85-
if apiErr.HTTPCode() == 403 {
83+
var googleErr *googleapi.Error
84+
if errors.As(err, &googleErr) {
85+
if googleErr.Code == http.StatusForbidden {
8686
if options.verbose {
8787
fmt.Printf("No access to project %s, skipping\n", project.ID)
8888
}

0 commit comments

Comments
 (0)