From da13c704845ff5b44b8d5075960287b57b8de14f Mon Sep 17 00:00:00 2001 From: Julien Castiaux Date: Tue, 30 Apr 2019 14:38:25 +0000 Subject: [PATCH] [FIX] google_account: error type on wrong request Configure google to be synchronized with Odoo, create a contact with a wrong email address (I used `foo@.test.`), create an event in the calendar, add the contact as attendee, sync with google. Traceback. The traceback is a `request.exception.HTTPError` reraise by `_do_request` in the `google.service` model on several HTTP errors, 400 amoung them. The real error is "Invalid attendee email." but the information is lost in the error message. The error hanlding has been rethink so it raise a user friendly error via the UserError modal with just the error message sent by the Google API. The logged error has been rethink to pretty print both the request and the response. opw-1974295 closes odoo/odoo#33058 Signed-off-by: Lucas Perais (lpe) --- addons/google_account/models/google_service.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/addons/google_account/models/google_service.py b/addons/google_account/models/google_service.py index 1797dd66bea..5292a490515 100644 --- a/addons/google_account/models/google_service.py +++ b/addons/google_account/models/google_service.py @@ -2,6 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from datetime import datetime +from pprint import pformat import json import logging @@ -183,13 +184,16 @@ class GoogleService(models.TransientModel): except: pass except requests.HTTPError as error: + # https://developers.google.com/calendar/v3/errors if error.response.status_code in (204, 404): status = error.response.status_code response = "" else: - _logger.exception("Bad google request : %s !", error.response.content) + req = json.loads(error.request.body) + res = error.response.json() + _logger.exception("Error while requesting Google Services\nRequest:\n%s\nResponse:\n%s", pformat(req), pformat(res)) if error.response.status_code in (400, 401, 410): - raise error + 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")) return (status, response, ask_time)