From e3f0219554772cebf9bd3e779b114d2bbd8356b5 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Fri, 1 Oct 2021 23:40:43 +0200 Subject: [PATCH] Errors should be caught also before a request action is executed (prevents HTTP timeouts when the error is on e.g. get_plugin() level) --- platypush/message/request/__init__.py | 32 +++++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/platypush/message/request/__init__.py b/platypush/message/request/__init__.py index 787b474f8a..40d189d4d0 100644 --- a/platypush/message/request/__init__.py +++ b/platypush/message/request/__init__.py @@ -207,21 +207,29 @@ class Request(Message): def _thread_func(_n_tries, errors=None): response = None - if self.action.startswith('procedure.'): - context['n_tries'] = _n_tries - response = self._execute_procedure(**context) - if response is not None: + try: + if self.action.startswith('procedure.'): + context['n_tries'] = _n_tries + response = self._execute_procedure(**context) + if response is not None: + self._send_response(response) + return response + # utils.get_context is a special action that simply returns the current context + elif self.action == 'utils.get_context': + response = Response(output=context) self._send_response(response) - return response - # utils.get_context is a special action that simply returns the current context - elif self.action == 'utils.get_context': - response = Response(output=context) + return response + else: + action = self.expand_value_from_context(self.action, **context) + (module_name, method_name) = get_module_and_method_from_action(action) + plugin = get_plugin(module_name) + except Exception as e: + logger.exception(e) + msg = 'Uncaught pre-processing exception from action [{}]: {}'.format(self.action, str(e)) + logger.warning(msg) + response = Response(output=None, errors=[msg]) self._send_response(response) return response - else: - action = self.expand_value_from_context(self.action, **context) - (module_name, method_name) = get_module_and_method_from_action(action) - plugin = get_plugin(module_name) try: # Run the action