From c580197a20021931910a0531b5e7eb577a2d428f Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Thu, 16 Jul 2020 15:51:50 +0000 Subject: [PATCH] [FIX] base: handle_exception should never alter json response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, in case you were in --dev-mode, if a json request crash, it was wrongly intercepted and return a Internal Server Error with status 500 and without the JSON Response For the change of http code, since it is only in dev mode, it could not impact a production server (in theory) with custom code based on it. After this commit, if your rpc fails, you will not have anymore a breakpoint in the code to help the developer to debug. But you will have a status 200 on the rpc request. closes odoo/odoo#54668 X-original-commit: 534cca311db1ecf1005a24d5cbd50e166094ba2a Signed-off-by: Olivier Dony (odo) Signed-off-by: Jérémy Kersten (jke) --- odoo/addons/base/models/ir_http.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/models/ir_http.py b/odoo/addons/base/models/ir_http.py index e7613af207a..ab2f903183d 100644 --- a/odoo/addons/base/models/ir_http.py +++ b/odoo/addons/base/models/ir_http.py @@ -194,7 +194,12 @@ class IrHttp(models.AbstractModel): return serve # Don't handle exception but use werkzeug debugger if server in --dev mode - if 'werkzeug' in tools.config['dev_mode'] and not isinstance(exception, werkzeug.exceptions.NotFound): + # Don't intercept JSON request to respect the JSON Spec and return exception as JSON + # "The Response is expressed as a single JSON Object, with the following members: + # jsonrpc, result, error, id" + if ('werkzeug' in tools.config['dev_mode'] + and not isinstance(exception, werkzeug.exceptions.NotFound) + and request._request_type != 'json'): raise exception try: