improved self-service error messages for zrok invite and zrok enable (#145)

This commit is contained in:
Michael Quigley 2023-01-12 13:02:32 -05:00
parent 71c0503bf4
commit 6035207f2e
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 35 additions and 17 deletions

View File

@ -57,7 +57,8 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
}
zrok, err := zrd.Client()
if err != nil {
panic(err)
cmd.endpointError(zrd.ApiEndpoint())
tui.Error("error creating service client", err)
}
auth := httptransport.APIKeyAuth("X-TOKEN", "header", token)
req := environment.NewEnableParams()
@ -87,6 +88,7 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
prg.Send(fmt.Sprintf("the zrok service returned an error: %v", err))
prg.Quit()
<-done
cmd.endpointError(zrd.ApiEndpoint())
os.Exit(1)
}
prg.Send("writing the environment details...")
@ -110,6 +112,14 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
<-done
}
func (cmd *enableCommand) endpointError(apiEndpoint, _ string) {
fmt.Printf("%v\n\n", tui.ErrorStyle.Render("there was a problem enabling your environment!"))
fmt.Printf("you are trying to use the zrok service at: %v\n\n", tui.CodeStyle.Render(apiEndpoint))
fmt.Printf("you can change your zrok service endpoint using this command:\n\n")
fmt.Printf("%v\n\n", tui.CodeStyle.Render("$ zrok config set apiEndpoint <newEndpoint>"))
fmt.Printf("(where newEndpoint is something like: %v)\n\n", tui.CodeStyle.Render("https://some.zrok.io"))
}
func getHost() (string, string, error) {
info, err := host.Info()
if err != nil {

View File

@ -44,6 +44,20 @@ func newInviteCommand() *inviteCommand {
}
func (cmd *inviteCommand) run(_ *cobra.Command, _ []string) {
zrd, err := zrokdir.Load()
if err != nil {
tui.Error("error loading zrokdir", err)
}
zrok, err := zrd.Client()
if err != nil {
if !panicInstead {
cmd.endpointError(zrd.ApiEndpoint())
tui.Error("error creating zrok api client", err)
}
panic(err)
}
if _, err := tea.NewProgram(&cmd.tui).Run(); err != nil {
tui.Error("unable to run interface", err)
os.Exit(1)
@ -51,18 +65,6 @@ func (cmd *inviteCommand) run(_ *cobra.Command, _ []string) {
if cmd.tui.done {
email := cmd.tui.inputs[0].Value()
zrd, err := zrokdir.Load()
if err != nil {
tui.Error("error loading zrokdir", err)
}
zrok, err := zrd.Client()
if err != nil {
if !panicInstead {
tui.Error("error creating zrok api client", err)
}
panic(err)
}
req := account.NewInviteParams()
req.Body = &rest_model_zrok.InviteRequest{
Email: email,
@ -70,16 +72,22 @@ func (cmd *inviteCommand) run(_ *cobra.Command, _ []string) {
}
_, err = zrok.Account.Invite(req)
if err != nil {
if !panicInstead {
tui.Error("error creating invitation", err)
}
panic(err)
cmd.endpointError(zrd.ApiEndpoint())
tui.Error("error creating invitation", err)
}
fmt.Printf("invitation sent to '%v'!\n", email)
}
}
func (cmd *inviteCommand) endpointError(apiEndpoint, _ string) {
fmt.Printf("%v\n\n", tui.ErrorStyle.Render("there was a problem creating an invitation!"))
fmt.Printf("you are trying to use the zrok service at: %v\n\n", tui.CodeStyle.Render(apiEndpoint))
fmt.Printf("you can change your zrok service endpoint using this command:\n\n")
fmt.Printf("%v\n\n", tui.CodeStyle.Render("$ zrok config set apiEndpoint <newEndpoint>"))
fmt.Printf("(where newEndpoint is something like: %v)\n\n", tui.CodeStyle.Render("https://some.zrok.io"))
}
type inviteTui struct {
focusIndex int
msg string