Handle unauthorized access to library

This commit is contained in:
Mathieu Comandon 2019-02-07 08:27:27 -08:00
parent 2ee79ed6ce
commit 9815b372fa
2 changed files with 21 additions and 5 deletions

View file

@ -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")

View file

@ -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: