From c444b5a2935b6a025aff607e55f3469c58c1e2da Mon Sep 17 00:00:00 2001 From: Wolfgang Taferner Date: Tue, 30 May 2017 15:49:41 +0200 Subject: [PATCH] [FIX] google_account: fix google request exception management Error thrown by google request is an urllib2.HTTPError that can be read and loaded in JSON. However in some cases the result of the read may be void or not JSON-ready. This was causing a crash in the error management and hid the actual issue. This commit tries to read and JSON-load the error but fall back on simply displaying the raw error in case of issue when handling it. Closes #17308 . --- addons/google_account/models/google_service.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/google_account/models/google_service.py b/addons/google_account/models/google_service.py index d707ee8d188..4c9ee092104 100644 --- a/addons/google_account/models/google_service.py +++ b/addons/google_account/models/google_service.py @@ -139,7 +139,11 @@ class GoogleService(models.TransientModel): if error.code == 400: # invalid grant with registry(request.session.db).cursor() as cur: self.env(cur)['res.users'].browse(self.env.uid).write({'google_%s_rtoken' % service: False}) - error_key = json.loads(error.read()).get("error", "nc") + try: + error_file = error.read() + error_key = json.loads(error_file).get("error", "nc") + except: + error_key = error _logger.exception("Bad google request : %s !", error_key) error_msg = _("Something went wrong during your token generation. Maybe your Authorization Code is invalid or already expired [%s]") % error_key raise self.env['res.config.settings'].get_config_warning(error_msg)