Skip to content

Commit

Permalink
fix: specific error message if token is invalid while saving cluster (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
manish-agrawal-ai authored Dec 13, 2022
1 parent 62cddc8 commit af7c5da
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/cluster/ClusterService.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"io/ioutil"
"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
v12 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -522,7 +523,14 @@ func (impl ClusterServiceImpl) CheckIfConfigIsValid(cluster *ClusterBean) error
return fmt.Errorf("Incorrect server url : %v", err)
} else if statusError, ok := err.(*errors.StatusError); ok {
if statusError != nil {
return fmt.Errorf("%s : %s", statusError.ErrStatus.Reason, statusError.ErrStatus.Message)
errReason := statusError.ErrStatus.Reason
var errMsg string
if errReason == v1.StatusReasonUnauthorized {
errMsg = "token seems invalid or does not have sufficient permissions"
} else {
errMsg = statusError.ErrStatus.Message
}
return fmt.Errorf("%s : %s", errReason, errMsg)
} else {
return fmt.Errorf("Validation failed : %v", err)
}
Expand Down

0 comments on commit af7c5da

Please sign in to comment.