[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 .
This commit is contained in:
Wolfgang Taferner
2017-06-01 11:28:43 +02:00
committed by Thibault Delavallée
parent 6e8516f9bf
commit c444b5a293
@@ -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)