[FIX] base: handle_exception should never alter json response

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) <odo@openerp.com>
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
This commit is contained in:
Jeremy Kersten
2020-07-17 12:47:59 +00:00
parent 11b1b82c09
commit c580197a20
+6 -1
View File
@@ -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: