From 9815b372fae9332a0efa71d43d09c1640f81e083 Mon Sep 17 00:00:00 2001 From: Mathieu Comandon Date: Thu, 7 Feb 2019 08:27:27 -0800 Subject: [PATCH] Handle unauthorized access to library --- lutris/gui/lutriswindow.py | 17 +++++++++++++---- lutris/util/http.py | 9 ++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lutris/gui/lutriswindow.py b/lutris/gui/lutriswindow.py index 844c3e6e5..0da910997 100644 --- a/lutris/gui/lutriswindow.py +++ b/lutris/gui/lutriswindow.py @@ -468,8 +468,14 @@ class LutrisWindow(Gtk.ApplicationWindow): """Synchronize games with local stuff and server.""" def update_gui(result, error): + self.sync_label.set_label("Synchronize library") + self.sync_spinner.props.active = False + self.sync_button.set_sensitive(True) if error: - logger.error("Failed to synchrone library: %s", error) + if isinstance(error, http.UnauthorizedAccess): + GLib.idle_add(self.show_invalid_credential_warning) + else: + GLib.idle_add(self.show_library_sync_error) return if result: added_ids, updated_ids = result @@ -478,9 +484,6 @@ class LutrisWindow(Gtk.ApplicationWindow): self.game_store.update_game_by_id(game_id) else: logger.error("No results returned when syncing the library") - self.sync_label.set_label("Synchronize library") - self.sync_spinner.props.active = False - self.sync_button.set_sensitive(True) self.sync_label.set_label("Synchronizing…") self.sync_spinner.props.active = True @@ -798,3 +801,9 @@ class LutrisWindow(Gtk.ApplicationWindow): self.game_store.filter_runner = self.selected_runner self.game_store.filter_platform = self.selected_platform self.invalidate_game_filter() + + def show_invalid_credential_warning(self): + dialogs.ErrorDialog("Could not connect to your Lutris account, please sign-in again.") + + def show_library_sync_error(self): + dialogs.ErrorDialog("Failed to retrieve game library, there might be some problems contacting lutris.net") diff --git a/lutris/util/http.py b/lutris/util/http.py index 7dc78a8e9..c44e35311 100644 --- a/lutris/util/http.py +++ b/lutris/util/http.py @@ -14,6 +14,10 @@ class HTTPError(Exception): """Exception raised on request failures""" +class UnauthorizedAccess(Exception): + """Exception raised for 401 HTTP errors""" + + class Request: def __init__( self, @@ -69,7 +73,10 @@ class Request: else: request = urllib.request.urlopen(req, timeout=self.timeout) except (urllib.error.HTTPError, CertificateError) as error: - raise HTTPError("Unavailable url %s: %s" % (self.url, error)) + if error.code == 401: + raise UnauthorizedAccess("Access to %s denied" % self.url) + else: + raise HTTPError("Request to %s failed: %s" % (self.url, error)) except (socket.timeout, urllib.error.URLError) as error: raise HTTPError("Unable to connect to server %s: %s" % (self.url, error)) if request.getcode() > 200: