summaryrefslogtreecommitdiff
path: root/state.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-09-06 12:54:50 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-09-06 12:54:50 +0200
commitc55c79fa5ec6eec660e944abae7412ff6d5a7943 (patch)
tree4436cf7ec068be81117487a3b75d41deb0b6fa0b /state.go
parent0d00fec9154bfd3f4dffb3d017d7c3eb795e4332 (diff)
State: Properly handle setting secure location error
Diffstat (limited to 'state.go')
-rw-r--r--state.go18
1 files changed, 15 insertions, 3 deletions
diff --git a/state.go b/state.go
index 55c3ec1..5a89083 100644
--- a/state.go
+++ b/state.go
@@ -1,6 +1,7 @@
package eduvpn
import (
+ "errors"
"fmt"
"github.com/jwijenbergh/eduvpn-common/internal/config"
@@ -160,13 +161,18 @@ func (state *VPNState) getConfig(
}
func (state *VPNState) SetSecureLocation(countryCode string) error {
- server, serverErr := state.Discovery.GetServerByCountryCode(countryCode, "secure_internet")
+ errorMessage := "failed asking secure location"
+ server, serverErr := state.Discovery.GetServerByCountryCode(countryCode, "secure_internet")
if serverErr != nil {
- return &types.WrappedErrorMessage{Message: "failed asking secure location", Err: serverErr}
+ return &types.WrappedErrorMessage{Message: errorMessage, Err: serverErr}
}
- state.Servers.SetSecureLocation(server, &state.FSM)
+ setLocationErr := state.Servers.SetSecureLocation(server, &state.FSM)
+ if setLocationErr != nil {
+ state.GoBack()
+ return &types.WrappedErrorMessage{Message: errorMessage, Err: setLocationErr}
+ }
return nil
}
@@ -175,6 +181,12 @@ func (state *VPNState) askSecureLocation() error {
// Ask for the location in the callback
state.FSM.GoTransitionWithData(fsm.ASK_LOCATION, locations, false)
+
+ // The state has changed, meaning setting the secure location was not successful
+ if state.FSM.Current != fsm.ASK_LOCATION {
+ // TODO: maybe a custom type for this errors.new?
+ return &types.WrappedErrorMessage{Message: "failed setting secure location", Err: errors.New("failed setting secure location due to state change. See the log file for more information")}
+ }
return nil
}