From 0c3496ac6833416c600cf73569842595ff305cdc Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Tue, 6 Sep 2022 16:53:44 +0200 Subject: State: Log fatal discovery errors if the app will fail to work --- state.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/state.go b/state.go index 2e0eb04..c949753 100644 --- a/state.go +++ b/state.go @@ -79,11 +79,23 @@ func (state *VPNState) Register( state.Logger.Log(log.LOG_INFO, "Previous configuration not found") } - // Go to the No Server state with the saved servers - state.FSM.GoTransitionWithData(fsm.NO_SERVER, state.GetSavedServers(), false) + discoServers, discoServersErr := state.GetDiscoServers() + + _, currentServerErr := state.Servers.GetCurrentServer() + // TODO: Log the error always + // Only actually return the error if we have no disco servers and no current server + if discoServersErr != nil && discoServers == "" && currentServerErr != nil { + return &types.WrappedErrorMessage{Message: errorMessage, Err: discoServersErr} + } + discoOrgs, discoOrgsErr := state.GetDiscoOrganizations() - state.GetDiscoServers() - state.GetDiscoOrganizations() + // TODO: Log the error always + // Only actually return the error if we have no disco servers and no current server + if discoOrgsErr != nil && discoOrgs == "" && currentServerErr != nil { + return &types.WrappedErrorMessage{Message: errorMessage, Err: discoOrgsErr} + } + // Go to the No Server state with the saved servers + state.FSM.GoTransitionWithData(fsm.NO_SERVER, state.GetSavedServers(), true) return nil } @@ -407,22 +419,10 @@ func (state *VPNState) ChangeSecureLocation() error { } func (state *VPNState) GetDiscoOrganizations() (string, error) { - if state.InFSMState(fsm.DEREGISTERED) { - return "", &types.WrappedErrorMessage{ - Message: "failed to get the organizations with Discovery", - Err: fsm.DeregisteredError{}.CustomError(), - } - } return state.Discovery.GetOrganizationsList() } func (state *VPNState) GetDiscoServers() (string, error) { - if state.InFSMState(fsm.DEREGISTERED) { - return "", &types.WrappedErrorMessage{ - Message: "failed to get the servers with Discovery", - Err: fsm.DeregisteredError{}.CustomError(), - } - } return state.Discovery.GetServersList() } -- cgit v1.2.3