summaryrefslogtreecommitdiff
path: root/state.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-09-26 14:50:22 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-09-26 15:33:04 +0200
commit7e4494256a08f585523e01b1bbc51f41ff4e2b95 (patch)
treeccbf873b2bfb11aa22f185e78ce1e2e5eebd094c /state.go
parent448c51d2142c186f0490b9d51c0d73beb3c76863 (diff)
Refactor: Errors into custom export types and expose types
Diffstat (limited to 'state.go')
-rw-r--r--state.go32
1 files changed, 14 insertions, 18 deletions
diff --git a/state.go b/state.go
index 933ede2..4e9f10e 100644
--- a/state.go
+++ b/state.go
@@ -10,7 +10,7 @@ import (
"github.com/eduvpn/eduvpn-common/internal/log"
"github.com/eduvpn/eduvpn-common/internal/oauth"
"github.com/eduvpn/eduvpn-common/internal/server"
- "github.com/eduvpn/eduvpn-common/internal/types"
+ "github.com/eduvpn/eduvpn-common/types"
"github.com/eduvpn/eduvpn-common/internal/util"
)
@@ -225,25 +225,25 @@ func (state *VPNState) retryConfigAuth(
errorMessage := "failed authorized config retry"
config, configType, configErr := state.getConfigAuth(chosenServer, forceTCP)
if configErr != nil {
+ level := types.ERR_OTHER
var error *oauth.OAuthTokensInvalidError
+ var oauthCancelledError *oauth.OAuthCancelledCallbackError
// Only retry if the error is that the tokens are invalid
if errors.As(configErr, &error) {
- retryConfig, retryConfigType, retryConfigErr := state.getConfigAuth(
+ config, configType, configErr = state.getConfigAuth(
chosenServer,
forceTCP,
)
- if retryConfigErr != nil {
- state.goBackInternal()
- return "", "", &types.WrappedErrorMessage{
- Message: errorMessage,
- Err: retryConfigErr,
- }
+ if configErr == nil {
+ return config, configType, nil
}
- return retryConfig, retryConfigType, nil
+ }
+ if errors.As(configErr, &oauthCancelledError) {
+ level = types.ERR_INFO
}
state.goBackInternal()
- return "", "", &types.WrappedErrorMessage{Message: errorMessage, Err: configErr}
+ return "", "", &types.WrappedErrorMessage{Level: level, Message: errorMessage, Err: configErr}
}
return config, configType, nil
}
@@ -263,7 +263,7 @@ func (state *VPNState) getConfig(
config, configType, configErr := state.retryConfigAuth(chosenServer, forceTCP)
if configErr != nil {
- return "", "", &types.WrappedErrorMessage{Message: errorMessage, Err: configErr}
+ return "", "", &types.WrappedErrorMessage{Level: GetErrorLevel(configErr), Message: errorMessage, Err: configErr}
}
currentServer, currentServerErr := state.Servers.GetCurrentServer()
@@ -484,7 +484,7 @@ func (state *VPNState) GetConfigSecureInternet(
GetErrorTraceback(configErr),
),
)
- return "", "", &types.WrappedErrorMessage{Message: errorMessage, Err: configErr}
+ return "", "", &types.WrappedErrorMessage{Level: GetErrorLevel(configErr), Message: errorMessage, Err: configErr}
}
return config, configType, nil
}
@@ -554,7 +554,7 @@ func (state *VPNState) GetConfigInstituteAccess(url string, forceTCP bool) (stri
GetErrorTraceback(configErr),
),
)
- return "", "", &types.WrappedErrorMessage{Message: errorMessage, Err: configErr}
+ return "", "", &types.WrappedErrorMessage{Level: GetErrorLevel(configErr), Message: errorMessage, Err: configErr}
}
return config, configType, nil
}
@@ -583,7 +583,7 @@ func (state *VPNState) GetConfigCustomServer(url string, forceTCP bool) (string,
GetErrorTraceback(configErr),
),
)
- return "", "", &types.WrappedErrorMessage{Message: errorMessage, Err: configErr}
+ return "", "", &types.WrappedErrorMessage{Level: GetErrorLevel(configErr), Message: errorMessage, Err: configErr}
}
return config, configType, nil
}
@@ -948,10 +948,6 @@ func GetErrorTraceback(err error) string {
return types.GetErrorTraceback(err)
}
-func GetErrorJSONString(err error) (string, error) {
- return types.GetErrorJSONString(err)
-}
-
func (state *VPNState) GetTranslated(languages map[string]string) string {
return util.GetLanguageMatched(languages, state.Language)
}