Nicer error message when book reading fails on Edge

This commit is contained in:
Kovid Goyal 2017-05-09 14:02:49 +05:30
parent e9d15b7dd2
commit 1ceb6af05f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -124,11 +124,17 @@ class DB:
transaction = self.idb.transaction(stores) transaction = self.idb.transaction(stores)
# Microsoft Edge currently does not support complex keys so the # Microsoft Edge currently does not support complex keys so the
# next line will throw a DataError in Edge when data is an # next line will throw a DataError in Edge when data is an
# object key like an array. You can probably show a nicer error # object key like an array.
# is Microsoft does not fix this and lots of users try to read
# books on Edge.
# https://gist.github.com/nolanlawson/a841ee23436410f37168 # https://gist.github.com/nolanlawson/a841ee23436410f37168
req = transaction.objectStore(store).get(data) try:
req = transaction.objectStore(store).get(data)
except Exception:
if /Edge\/\d+/.test(window.navigator.userAgent):
self.show_error(_('Cannot read book'), _(
'Reading of books is not supported on Microsoft Edge. Use a better'
' browser such as Google Chrome or Mozilla Firefox'))
return
raise
req.onsuccess = def(event): proceed(req.result) req.onsuccess = def(event): proceed(req.result)
elif op is 'put': elif op is 'put':
transaction = self.idb.transaction(stores, 'readwrite') transaction = self.idb.transaction(stores, 'readwrite')