From adba55eb7dc924a9ef9701f3dc888606b7ab10fc Mon Sep 17 00:00:00 2001 From: blitzmann Date: Sun, 24 Oct 2021 14:07:04 -0400 Subject: [PATCH] Ensure that the token error dialog spawns n the three most used API calls that might trigger token refresh: fetch skills, fetch fits, and export fit --- gui/characterEditor.py | 31 +++++++++++++++++++++++-------- gui/characterSelection.py | 10 ++-------- gui/esiFittings.py | 29 +++++++++++++++-------------- 3 files changed, 40 insertions(+), 30 deletions(-) diff --git a/gui/characterEditor.py b/gui/characterEditor.py index 20130075a..9f268556d 100644 --- a/gui/characterEditor.py +++ b/gui/characterEditor.py @@ -42,6 +42,7 @@ from gui.contextMenu import ContextMenu from gui.utils.clipboard import fromClipboard, toClipboard from service.character import Character from service.esi import Esi +from service.esiAccess import APIException from service.fit import Fit from service.market import Market @@ -888,14 +889,7 @@ class APIView(wx.Panel): def fetchCallback(e=None): if e: pyfalog.warn("Error fetching skill information for character for __fetchCallback") - exc_type, exc_value, exc_trace = e - if config.debug: - exc_value = ''.join(traceback.format_exception(exc_type, exc_value, exc_trace)) - pyfalog.warn(exc_value) - - wx.MessageBox( - _t("Error fetching skill information"), - _t("Error"), wx.ICON_ERROR | wx.STAY_ON_TOP) + SkillFetchExceptionHandler(e) else: wx.MessageBox( _t("Successfully fetched skills"), _t("Success"), wx.ICON_INFORMATION | wx.STAY_ON_TOP) @@ -926,3 +920,24 @@ class SecStatusDialog(wx.Dialog): self.Layout() self.Center(wx.BOTH) + + +class SkillFetchExceptionHandler: + def __init__(self, e): + from gui.esiFittings import ESIExceptionHandler + exc_type, exc_value, exc_trace = e + if config.debug: + exc_value = ''.join(traceback.format_exception(exc_type, exc_value, exc_trace)) + pyfalog.warn(exc_value) + + try: + try: + raise exc_value + except APIException as ex: + pyfalog.error(ex) + ESIExceptionHandler(ex) + except Exception as ex: + pyfalog.error(ex) + wx.MessageBox( + _t("Error fetching skill information"), + _t("Error"), wx.ICON_ERROR | wx.STAY_ON_TOP) diff --git a/gui/characterSelection.py b/gui/characterSelection.py index d403fa8bf..a248d7345 100644 --- a/gui/characterSelection.py +++ b/gui/characterSelection.py @@ -163,15 +163,9 @@ class CharacterSelection(wx.Panel): if e is None: self.refreshCharacterList() else: + from gui.characterEditor import SkillFetchExceptionHandler pyfalog.warn("Error fetching skill information for character for refreshAPICallback") - exc_type, exc_value, exc_trace = e - if config.debug: - exc_value = ''.join(traceback.format_exception(exc_type, exc_value, exc_trace)) - pyfalog.warn(exc_value) - - wx.MessageBox( - _t("Error fetching skill information"), - _t("Error"), wx.ICON_ERROR | wx.STAY_ON_TOP) + SkillFetchExceptionHandler(e) def charChanged(self, event): fitID = self.mainFrame.getActiveFit() diff --git a/gui/esiFittings.py b/gui/esiFittings.py index 3136076a3..f5cbd1591 100644 --- a/gui/esiFittings.py +++ b/gui/esiFittings.py @@ -133,7 +133,7 @@ class EveFittings(AuxiliaryFrame): except APIException as ex: # Can't do this in a finally because then it obscures the message dialog del waitDialog # noqa: F821 - ESIExceptionHandler(self, ex) + ESIExceptionHandler(ex) except (KeyboardInterrupt, SystemExit): raise except Exception as ex: @@ -223,13 +223,14 @@ class ESIServerExceptionHandler: class ESIExceptionHandler: # todo: make this a generate excetpion handler for all calls - def __init__(self, parentWindow, ex): + def __init__(self, ex): + # raise ex if ex.response['error'].startswith('Token is not valid') \ or ex.response['error'] == 'invalid_token' \ or ex.response['error'] == 'invalid_grant': # todo: this seems messy, figure out a better response pyfalog.error(ex) with wx.MessageDialog( - parentWindow, + gui.mainFrame.MainFrame.getInstance(), _t("There was an error validating characters' SSO token. Please try " "logging into the character again to reset the token."), _t("Invalid Token"), @@ -343,9 +344,9 @@ class ExportToEve(AuxiliaryFrame): pyfalog.warning(msg) self.statusbar.SetStatusText(msg, 1) return - res = sEsi.postFitting(activeChar, data) try: + res = sEsi.postFitting(activeChar, data) res.raise_for_status() self.statusbar.SetStatusText("", 0) self.statusbar.SetStatusText(res.reason, 1) @@ -354,19 +355,19 @@ class ExportToEve(AuxiliaryFrame): pyfalog.error(msg) self.statusbar.SetStatusText(_t("ERROR"), 0) self.statusbar.SetStatusText(msg, 1) - except ESIExportException as ex: + except APIException as ex: pyfalog.error(ex) self.statusbar.SetStatusText(_t("ERROR"), 0) - self.statusbar.SetStatusText("{} - {}".format(res.status_code, res.reason), 1) - except APIException as ex: + self.statusbar.SetStatusText("HTTP {} - {}".format(ex.status_code, ex.response["error"]), 1) try: - ESIExceptionHandler(self, ex) - except (KeyboardInterrupt, SystemExit): - raise - except Exception as ex: - self.statusbar.SetStatusText(_t("ERROR"), 0) - self.statusbar.SetStatusText("{} - {}".format(res.status_code, res.reason), 1) - pyfalog.error(ex) + ESIExceptionHandler(ex) + except: + # don't need to do anything - we should already get the error in ex.response + pass + except Exception as ex: + self.statusbar.SetStatusText(_t("ERROR"), 0) + self.statusbar.SetStatusText("Unknown error", 1) + pyfalog.error(ex) class SsoCharacterMgmt(AuxiliaryFrame):