mirror of
https://github.com/openziti/zrok.git
synced 2025-06-06 18:06:43 +02:00
'http backend' error handling improvements; ui.Close (#67)
This commit is contained in:
parent
72b3f31ebe
commit
4e08dd379c
@ -50,6 +50,9 @@ func newHttpBackendCommand() *httpBackendCommand {
|
|||||||
func (self *httpBackendCommand) run(_ *cobra.Command, args []string) {
|
func (self *httpBackendCommand) run(_ *cobra.Command, args []string) {
|
||||||
if !self.quiet {
|
if !self.quiet {
|
||||||
if err := ui.Init(); err != nil {
|
if err := ui.Init(); err != nil {
|
||||||
|
if !panicInstead {
|
||||||
|
showError("unable to initialize user interface", err)
|
||||||
|
}
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
defer ui.Close()
|
defer ui.Close()
|
||||||
@ -58,10 +61,18 @@ func (self *httpBackendCommand) run(_ *cobra.Command, args []string) {
|
|||||||
|
|
||||||
env, err := zrokdir.LoadEnvironment()
|
env, err := zrokdir.LoadEnvironment()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
ui.Close()
|
||||||
|
if !panicInstead {
|
||||||
|
showError("unable to load environment; did you 'zrok enable'?", err)
|
||||||
|
}
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
zif, err := zrokdir.ZitiIdentityFile("environment")
|
zif, err := zrokdir.ZitiIdentityFile("environment")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
ui.Close()
|
||||||
|
if !panicInstead {
|
||||||
|
showError("unable to load ziti identity configuration", err)
|
||||||
|
}
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
cfg := &backend.Config{
|
cfg := &backend.Config{
|
||||||
@ -71,6 +82,10 @@ func (self *httpBackendCommand) run(_ *cobra.Command, args []string) {
|
|||||||
|
|
||||||
zrok, err := newZrokClient(env.ApiEndpoint)
|
zrok, err := newZrokClient(env.ApiEndpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
ui.Close()
|
||||||
|
if !panicInstead {
|
||||||
|
showError("unable to create zrok client", err)
|
||||||
|
}
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
auth := httptransport.APIKeyAuth("X-TOKEN", "header", env.ZrokToken)
|
auth := httptransport.APIKeyAuth("X-TOKEN", "header", env.ZrokToken)
|
||||||
@ -94,6 +109,10 @@ func (self *httpBackendCommand) run(_ *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
resp, err := zrok.Tunnel.Tunnel(req, auth)
|
resp, err := zrok.Tunnel.Tunnel(req, auth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
ui.Close()
|
||||||
|
if !panicInstead {
|
||||||
|
showError("unable to create tunnel", err)
|
||||||
|
}
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
cfg.Service = resp.Payload.Service
|
cfg.Service = resp.Payload.Service
|
||||||
@ -108,11 +127,18 @@ func (self *httpBackendCommand) run(_ *cobra.Command, args []string) {
|
|||||||
|
|
||||||
httpProxy, err := backend.NewHTTP(cfg)
|
httpProxy, err := backend.NewHTTP(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
ui.Close()
|
||||||
|
if !panicInstead {
|
||||||
|
showError("unable to create http backend", err)
|
||||||
|
}
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if err := httpProxy.Run(); err != nil {
|
if err := httpProxy.Run(); err != nil {
|
||||||
|
if !panicInstead {
|
||||||
|
showError("unable to run http proxy", err)
|
||||||
|
}
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user