diff --git a/gui/crestFittings.py b/gui/crestFittings.py index 32c863812..46ad72663 100644 --- a/gui/crestFittings.py +++ b/gui/crestFittings.py @@ -17,6 +17,8 @@ import gui.globalEvents as GE from logbook import Logger import calendar from service.esi import Esi +from esipy.exceptions import APIException + pyfalog = Logger(__name__) @@ -131,8 +133,9 @@ class CrestFittings(wx.Frame): def fetchFittings(self, event): sCrest = Esi.getInstance() + waitDialog = wx.BusyInfo("Fetching fits, please wait...", parent=self) + try: - waitDialog = wx.BusyInfo("Fetching fits, please wait...", parent=self) fittings = sCrest.getFittings(self.getActiveCharacter()) # self.cacheTime = fittings.get('cached_until') # self.updateCacheStatus(None) @@ -143,6 +146,12 @@ class CrestFittings(wx.Frame): msg = "Connection error, please check your internet connection" pyfalog.error(msg) self.statusbar.SetStatusText(msg) + except APIException as ex: + del waitDialog # Can't do this in a finally because then it obscures the message dialog + ESIExceptionHandler(self, ex) + except Exception as ex: + del waitDialog + def importFitting(self, event): selection = self.fitView.fitSelection @@ -173,6 +182,20 @@ class CrestFittings(wx.Frame): self.statusbar.SetStatusText(msg) +class ESIExceptionHandler(object): + def __init__(self, parentWindow, ex): + if ex.response['error'] == "invalid_token": + dlg = wx.MessageDialog(parentWindow, + "There was an error retrieving fits for the selected character due to an invalid token. Please try " + "logging into the character again to reset the token.", "Invalid Token", + wx.OK | wx.ICON_ERROR) + dlg.ShowModal() + pyfalog.error(ex) + else: + # We don't know how to handle the error, raise it for the global error handler to pick it up + raise ex + + class ExportToEve(wx.Frame): def __init__(self, parent): wx.Frame.__init__(self, parent, id=wx.ID_ANY, title="Export fit to EVE", pos=wx.DefaultPosition, diff --git a/service/esi.py b/service/esi.py index f1b1e5b1d..274797af6 100644 --- a/service/esi.py +++ b/service/esi.py @@ -227,12 +227,13 @@ class Esi(object): cdata = esisecurity.verify() print(cdata) - currentCharacter = self.getSsoCharacter(cdata['CharacterID']) + currentCharacter = self.getSsoCharacter(cdata['CharacterName']) if currentCharacter is None: currentCharacter = SsoCharacter(cdata['CharacterID'], cdata['CharacterName'], config.getClientSecret()) currentCharacter.esi_client = Esi.genEsiClient(esisecurity) - Esi.update_token(currentCharacter, auth_response) # this also sets the esi security token + + Esi.update_token(currentCharacter, auth_response) # this also sets the esi security token eos.db.save(currentCharacter) diff --git a/service/server.py b/service/server.py index 34261294a..48e386451 100644 --- a/service/server.py +++ b/service/server.py @@ -85,7 +85,7 @@ class AuthHandler(http.server.BaseHTTPRequestHandler): pyfalog.info("Successfully logged into EVE.") msg = "If you see this message then it means you should be logged into CREST. You may close this window and return to the application." else: - # For implicit mode, we have to serve up the page which will take the hash and redirect useing a querystring + # For implicit mode, we have to serve up the page which will take the hash and redirect using a querystring pyfalog.info("Processing response from EVE Online.") msg = "Processing response from EVE Online" except Exception as ex: