From 4d6299f0d50b6f115d11cf529ed462525907a3a2 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 29 Jul 2018 17:51:23 +0200 Subject: [PATCH] Improved gdrive error messages (#554) --- cps/gdriveutils.py | 7 +++++-- cps/web.py | 7 ++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cps/gdriveutils.py b/cps/gdriveutils.py index 1d722e0c..17e51f0c 100644 --- a/cps/gdriveutils.py +++ b/cps/gdriveutils.py @@ -1,6 +1,7 @@ try: from pydrive.auth import GoogleAuth from pydrive.drive import GoogleDrive + from pydrive.auth import RefreshError from apiclient import errors except ImportError: pass @@ -132,8 +133,10 @@ def getDrive(drive=None, gauth=None): # Refresh them if expired try: gauth.Refresh() - except: - web.app.logger.error("Google Drive gdrive_credentials file not present, reauthenticate in config section") + except RefreshError as e: + web.app.logger.error("Google Drive error: " + e.message) + except Exception as e: + web.app.logger.exception(e) else: # Initialize the saved creds gauth.Authorize() diff --git a/cps/web.py b/cps/web.py index 6598064b..4a93b343 100755 --- a/cps/web.py +++ b/cps/web.py @@ -1800,7 +1800,8 @@ def get_cover(cover_path): app.logger.error(cover_path + '/cover.jpg not found on Google Drive') return send_from_directory(os.path.join(os.path.dirname(__file__), "static"), "generic_cover.jpg") except Exception as e: - app.logger.error("Message "+e.message) + app.logger.error("Error Message: "+e.message) + app.logger.exception(e) # traceback.print_exc() return send_from_directory(os.path.join(os.path.dirname(__file__), "static"),"generic_cover.jpg") else: @@ -2721,7 +2722,7 @@ def configuration_helper(origin): config.loadSettings() app.logger.setLevel(config.config_log_level) logging.getLogger("book_formats").setLevel(config.config_log_level) - except e: + except Exception as e: flash(e, category="error") return render_title_template("config_edit.html", content=config, origin=origin, gdrive=gdrive_support, gdriveError=gdriveError, goodreads=goodreads_support, @@ -2846,7 +2847,7 @@ def edit_mailsettings(): try: ub.session.commit() flash(_(u"Mail settings updated"), category="success") - except e: + except Exception as e: flash(e, category="error") if "test" in to_save and to_save["test"]: if current_user.kindle_mail: