瀏覽代碼

add error when not logged in (#3974)

d-g-town 2 年之前
父節點
當前提交
87331ab827
共有 1 個文件被更改,包括 2 次插入2 次删除
  1. 2 2
      cli/cmd/commands/errors.go

+ 2 - 2
cli/cmd/commands/errors.go

@@ -25,6 +25,7 @@ type authenticatedRunnerFunc func(ctx context.Context, user *types.GetAuthentica
 func checkLoginAndRunWithConfig(cmd *cobra.Command, cliConf config.CLIConfig, args []string, runner authenticatedRunnerFunc) error {
 	ctx := cmd.Context()
 	cliConf = overrideConfigWithFlags(cmd, cliConf)
+	red := color.New(color.FgRed)
 
 	client, err := api.NewClientWithConfig(ctx, api.NewClientInput{
 		BaseURL:        fmt.Sprintf("%s/api", cliConf.Host),
@@ -32,13 +33,12 @@ func checkLoginAndRunWithConfig(cmd *cobra.Command, cliConf config.CLIConfig, ar
 		CookieFileName: "cookie.json",
 	})
 	if err != nil {
+		red.Print("You are not logged in. Log in using \"porter auth login\"\n") // nolint:errcheck,gosec
 		return fmt.Errorf("error creating porter API client: %w", err)
 	}
 
 	user, err := client.AuthCheck(ctx)
 	if err != nil {
-		red := color.New(color.FgRed)
-
 		if strings.Contains(err.Error(), "Forbidden") {
 			red.Print("You are not logged in. Log in using \"porter auth login\"\n")
 			return ErrNotLoggedIn