summaryrefslogtreecommitdiff
path: root/addons/google_account
diff options
context:
space:
mode:
authorJulien Castiaux <juc@odoo.com>2019-06-18 14:09:23 +0000
committerJulien Castiaux <juc@odoo.com>2019-06-19 09:12:27 +0000
commit85ab9238c5b6cb7db259b4c2e1d67a34fe1c4606 (patch)
treedf1d0d6db18b8c7026b051945e1ccb9cd77c4c37 /addons/google_account
parent3b1699e02d4483913159681bf7e10839e6493244 (diff)
[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 <Julien00859@users.noreply.github.com>
Diffstat (limited to 'addons/google_account')
-rw-r--r--addons/google_account/i18n/google_account.pot16
-rw-r--r--addons/google_account/models/google_service.py22
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