Skip to content

Commit

Permalink
handle additional scenario
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Falzetti <andrea@okteto.com>
  • Loading branch information
andreafalzetti committed May 20, 2024
1 parent 582641f commit b039f9b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/okteto/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/http"
"net/url"
"os"
"regexp"
"strings"
"sync"

Expand Down Expand Up @@ -55,6 +56,10 @@ var serverName string
var strictTLSOnce sync.Once
var errURLNotSet = errors.New("the okteto URL is not set")

const unauthorizedTokenPattern = `^non-200 OK status code: 401 Unauthorized body: "fail to find user with token [A-Za-z0-9]+: not-authorized\\n"$`

var unauthorizedTokenRegex = regexp.MustCompile(unauthorizedTokenPattern)

// graphqlClientInterface contains the functions that a graphqlClient must have
type graphqlClientInterface interface {
Query(ctx context.Context, q interface{}, variables map[string]interface{}) error
Expand Down Expand Up @@ -352,6 +357,10 @@ func translateAPIErr(err error) error {
return oktetoErrors.ErrNotFound

default:
if unauthorizedTokenRegex.MatchString(err.Error()) {

This comment has been minimized.

Copy link
@jLopezbarb

jLopezbarb May 20, 2024

Contributor

NIT: Could we move this into the switch on line 364? I think having several ifs and switches can be misleading. Other than that the PR seems ok to me

return fmt.Errorf(oktetoErrors.ErrNotLogged, GetContext().Name)
}

switch {
case oktetoErrors.IsX509(err):
return oktetoErrors.UserError{
Expand All @@ -368,7 +377,6 @@ func translateAPIErr(err error) error {
oktetoLog.Infof("Unrecognized API error: %s", err)
return err
}

}

func isAPILicenseError(err error) bool {
Expand Down

0 comments on commit b039f9b

Please sign in to comment.