From 85ab9238c5b6cb7db259b4c2e1d67a34fe1c4606 Mon Sep 17 00:00:00 2001 From: Julien Castiaux Date: Tue, 18 Jun 2019 14:09:23 +0000 Subject: [PATCH] [FIX] google_account: improve logging of errors There is no guaranty that both the request body and the response body will contain JSON data. This fix corrects the logging by printing the raw text in case of json decode error. opw-2006561 opw-2024242 closes odoo/odoo#34221 Signed-off-by: Julien Castiaux --- addons/google_account/i18n/google_account.pot | 16 ++++++++++++-- .../google_account/models/google_service.py | 22 ++++++++++++++----- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/addons/google_account/i18n/google_account.pot b/addons/google_account/i18n/google_account.pot index c417f0ab441..e3bacbffe16 100644 --- a/addons/google_account/i18n/google_account.pot +++ b/addons/google_account/i18n/google_account.pot @@ -31,7 +31,13 @@ msgid "Display Name" msgstr "" #. module: google_account -#: code:addons/google_account/models/google_service.py:196 +#: code:addons/google_account/models/google_service.py:203 +#, python-format +msgid "Error while requesting Google Services" +msgstr "" + +#. module: google_account +#: code:addons/google_account/models/google_service.py:199 #, python-format msgid "Error while requesting Google Services: %s" msgstr "" @@ -86,7 +92,13 @@ msgid "Something went wrong during your token generation. Maybe your Authorizati msgstr "" #. module: google_account -#: code:addons/google_account/models/google_service.py:197 +#: code:addons/google_account/models/google_service.py:204 +#, python-format +msgid "Something went wrong with your request to google" +msgstr "" + +#. module: google_account +#: code:addons/google_account/models/google_service.py:200 #, python-format msgid "Something went wrong with your request to google: %s" msgstr "" diff --git a/addons/google_account/models/google_service.py b/addons/google_account/models/google_service.py index fb9213f96b2..aa3040d7947 100644 --- a/addons/google_account/models/google_service.py +++ b/addons/google_account/models/google_service.py @@ -189,12 +189,24 @@ class GoogleService(models.TransientModel): status = error.response.status_code response = "" else: - req = json.loads(error.request.body or 'null') - res = error.response.json() - _logger.exception("Error while requesting Google Services\nRequest:\n%s\nResponse:\n%s", pformat(req), pformat(res)) + try: + exception_req = pformat(json.loads(error.request.body)) + except: + exception_req = error.request.body + + try: + exception_res = pformat(error.response.json()) + error_msg = _("Error while requesting Google Services: %s") % res['error']['message'] + warning_msg = _("Something went wrong with your request to google: %s") % res['error']['message'] + except: + exception_res = error.response.text + error_msg = _("Error while requesting Google Services") + warning_msg = _("Something went wrong with your request to google") + + _logger.exception("Error while requesting Google Services\nRequest:\n%s\nResponse:\n%s", exception_req, exception_res) if error.response.status_code in (400, 401, 410): - raise UserError(_("Error while requesting Google Services: %s") % res['error']['message']) - raise self.env['res.config.settings'].get_config_warning(_("Something went wrong with your request to google: %s") % res['error']['message']) + raise UserError(error_msg) + raise self.env['res.config.settings'].get_config_warning(warning_msg) return (status, response, ask_time) # TODO : remove me, it is only used in google calendar. Make google_calendar use the constants