Skip to content

Commit ed48a8b

Browse files
committed
Re-work the exceptions related to logging a character in
1 parent 5a6fe37 commit ed48a8b

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

gui/esiFittings.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -227,21 +227,6 @@ def deleteAllFittings(self, event):
227227
self.fitView.update([])
228228

229229

230-
class ESIServerExceptionHandler:
231-
def __init__(self, parentWindow, ex):
232-
pyfalog.error(ex)
233-
with wx.MessageDialog(
234-
parentWindow,
235-
_t("There was an issue starting up the localized server, try setting "
236-
"Login Authentication Method to Manual by going to Preferences -> EVE SS0 -> "
237-
"Login Authentication Method. If this doesn't fix the problem please file an "
238-
"issue on Github."),
239-
_t("Add Character Error"),
240-
wx.OK | wx.ICON_ERROR
241-
) as dlg:
242-
dlg.ShowModal()
243-
244-
245230
class ESIExceptionHandler:
246231
# todo: make this a generate excetpion handler for all calls
247232
def __init__(self, ex):

gui/ssoLogin.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,16 @@ def __init__(self, server: config.ApiServer, start_local_server=True):
6060
if server.name == "Serenity":
6161
webbrowser.open(config.SSO_LOGOFF_SERENITY)
6262
time.sleep(1)
63+
6364
self.okBtn = self.FindWindow(wx.ID_OK)
64-
webbrowser.open(uri)
6565
self.okBtn.Enable(False)
66+
# Ensure we clean up once they hit the "OK" button
67+
self.okBtn.Bind(wx.EVT_BUTTON, self.OnDestroy)
68+
69+
webbrowser.open(uri)
6670

6771
self.mainFrame.Bind(GE.EVT_SSO_LOGIN, self.OnLogin)
72+
# Ensure we clean up if ESC is pressed
6873
self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
6974

7075
def OnTextEnter(self, event):
@@ -76,10 +81,13 @@ def OnTextEnter(self, event):
7681
event.Skip()
7782

7883
def OnLogin(self, event):
84+
# This would normally happen if it was logged in via server auto-login. In this case, the modal is done, we effectively want to cancel out
7985
self.EndModal(wx.ID_CANCEL)
8086
event.Skip()
8187

8288
def OnDestroy(self, event):
89+
# Clean up by unbinding some events and stopping the server
8390
self.mainFrame.Unbind(GE.EVT_SSO_LOGIN, handler=self.OnLogin)
91+
self.Unbind(wx.EVT_WINDOW_DESTROY, handler=self.OnDestroy)
8492
self.sEsi.stopServer()
8593
event.Skip()

service/esi.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from requests import Session
2323

2424
pyfalog = Logger(__name__)
25+
_t = wx.GetTranslation
2526

2627

2728
class Esi(EsiAccess):
@@ -104,16 +105,32 @@ def login(self):
104105
start_server = self.settings.get('loginMode') == EsiLoginMethod.SERVER and self.server_base.supports_auto_login
105106
with gui.ssoLogin.SsoLogin(self.server_base, start_server) as dlg:
106107
if dlg.ShowModal() == wx.ID_OK:
107-
if self.default_server_name == "Serenity":
108-
s = re.search(r'(?<=code=)[a-zA-Z0-9\-_]*', dlg.ssoInfoCtrl.Value.strip())
109-
if s:
110-
# skip state verification and go directly through the auth code processing
111-
self.handleLogin(s.group)
108+
from gui.esiFittings import ESIExceptionHandler
109+
110+
try:
111+
if self.default_server_name == "Serenity":
112+
s = re.search(r'(?<=code=)[a-zA-Z0-9\-_]*', dlg.ssoInfoCtrl.Value.strip())
113+
if s:
114+
# skip state verification and go directly through the auth code processing
115+
self.handleLogin(s.group)
116+
else:
117+
pass
118+
# todo: throw error
112119
else:
113-
pass
114-
# todo: throw error
115-
else:
116-
self.handleServerRequest(json.loads(base64.b64decode(dlg.ssoInfoCtrl.Value.strip())))
120+
self.handleServerRequest(json.loads(base64.b64decode(dlg.ssoInfoCtrl.Value.strip())))
121+
except GenericSsoError as ex:
122+
pyfalog.error(ex)
123+
with wx.MessageDialog(
124+
self.mainFrame,
125+
str(ex),
126+
_t("SSO Error"),
127+
wx.OK | wx.ICON_ERROR
128+
) as dlg:
129+
dlg.ShowModal()
130+
except APIException as ex:
131+
pyfalog.error(ex)
132+
ESIExceptionHandler(ex)
133+
pass
117134

118135

119136
def stopServer(self):

0 commit comments

Comments
 (0)