Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Modifying error message if invalid token is provided while saving cluster #2760

Merged
merged 2 commits into from
Dec 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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