summaryrefslogtreecommitdiff
path: root/odoo
diff options
context:
space:
mode:
authorCedric Snauwaert <csn@openerp.com>2020-02-18 12:53:00 +0000
committerCedric Snauwaert <csn@openerp.com>2020-02-18 14:50:57 +0000
commit07d5ea3779d796f621ce4cc5f9c2caa940d2012e (patch)
tree675402cacdae3ca52c7b1abc4533550c4f3c155c /odoo
parent60b0f6da3420e0bb0607bd73abb4d0a1f5a0a972 (diff)
[FIX] http.py: remove try except in JsonRequest.dispatch()
The idea is to make the dispatching and error-handling consistent for JsonRequest and HTTPRequest. In 8809c77f6088c140355fba5f862c0335b1d90c4e we introduced a way for request-specific error-handling, but JsonRequest.dispatch() was still catching all errors internally, instead of letting them bubble up to ir_http._handle_exception() By removing the internal try except in JsonRequest.dispatch(), we do not change the behavior much as there are only a couple of "if" in ir_http._handle_exception() before returning to the request-specific handle_exception. However we give the opportunity to modules to customize exception handling even for JsonRPC, the same way it is possible for HTTP requests. Here is a simple pseudo code of the flow ir_http.dispatch(): try: request.dispatch() catch Exception as e: ir_http._handle_exception(e) ir_http.handle_exception(e) request._handle_exception(e) closes odoo/odoo#45639 Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
Diffstat (limited to 'odoo')
-rw-r--r--odoo/http.py64
1 files changed, 30 insertions, 34 deletions
diff --git a/odoo/http.py b/odoo/http.py
index 4c0cf76005c..3b2a6468cf3 100644
--- a/odoo/http.py
+++ b/odoo/http.py
@@ -606,7 +606,6 @@ class JsonRequest(WebRequest):
self.context = self.params.pop('context', dict(self.session.context))
def _json_response(self, result=None, error=None):
-
response = {
'jsonrpc': '2.0',
'id': self.jsonrequest.get('id')
@@ -657,40 +656,37 @@ class JsonRequest(WebRequest):
return self._json_response(error=error)
def dispatch(self):
- try:
- rpc_request_flag = rpc_request.isEnabledFor(logging.DEBUG)
- rpc_response_flag = rpc_response.isEnabledFor(logging.DEBUG)
- if rpc_request_flag or rpc_response_flag:
- endpoint = self.endpoint.method.__name__
- model = self.params.get('model')
- method = self.params.get('method')
- args = self.params.get('args', [])
-
- start_time = time.time()
- start_memory = 0
- if psutil:
- start_memory = memory_info(psutil.Process(os.getpid()))
- if rpc_request and rpc_response_flag:
- rpc_request.debug('%s: %s %s, %s',
- endpoint, model, method, pprint.pformat(args))
-
- result = self._call_function(**self.params)
-
- if rpc_request_flag or rpc_response_flag:
- end_time = time.time()
- end_memory = 0
- if psutil:
- end_memory = memory_info(psutil.Process(os.getpid()))
- logline = '%s: %s %s: time:%.3fs mem: %sk -> %sk (diff: %sk)' % (
- endpoint, model, method, end_time - start_time, start_memory / 1024, end_memory / 1024, (end_memory - start_memory)/1024)
- if rpc_response_flag:
- rpc_response.debug('%s, %s', logline, pprint.pformat(result))
- else:
- rpc_request.debug(logline)
+ rpc_request_flag = rpc_request.isEnabledFor(logging.DEBUG)
+ rpc_response_flag = rpc_response.isEnabledFor(logging.DEBUG)
+ if rpc_request_flag or rpc_response_flag:
+ endpoint = self.endpoint.method.__name__
+ model = self.params.get('model')
+ method = self.params.get('method')
+ args = self.params.get('args', [])
+
+ start_time = time.time()
+ start_memory = 0
+ if psutil:
+ start_memory = memory_info(psutil.Process(os.getpid()))
+ if rpc_request and rpc_response_flag:
+ rpc_request.debug('%s: %s %s, %s',
+ endpoint, model, method, pprint.pformat(args))
+
+ result = self._call_function(**self.params)
+
+ if rpc_request_flag or rpc_response_flag:
+ end_time = time.time()
+ end_memory = 0
+ if psutil:
+ end_memory = memory_info(psutil.Process(os.getpid()))
+ logline = '%s: %s %s: time:%.3fs mem: %sk -> %sk (diff: %sk)' % (
+ endpoint, model, method, end_time - start_time, start_memory / 1024, end_memory / 1024, (end_memory - start_memory)/1024)
+ if rpc_response_flag:
+ rpc_response.debug('%s, %s', logline, pprint.pformat(result))
+ else:
+ rpc_request.debug(logline)
- return self._json_response(result)
- except Exception as e:
- return self._handle_exception(e)
+ return self._json_response(result)
def serialize_exception(e):