forked from platypush/platypush
Catch TypeError when execution an action.
Most of TypeError are due to the user passing wrong data. It usually doesn't mean that we have to fail hard and reload the plugin, nor retry the call with the same parameters.
This commit is contained in:
parent
27cf1bec52
commit
cb04af0bbd
1 changed files with 6 additions and 1 deletions
|
@ -15,6 +15,7 @@ from platypush.message.response import Response
|
|||
from platypush.utils import get_decorators, get_plugin_name_by_class
|
||||
|
||||
PLUGIN_STOP_TIMEOUT = 5 # Plugin stop timeout in seconds
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def action(f: Callable[..., Any]) -> Callable[..., Response]:
|
||||
|
@ -29,7 +30,11 @@ def action(f: Callable[..., Any]) -> Callable[..., Response]:
|
|||
@wraps(f)
|
||||
def _execute_action(*args, **kwargs) -> Response:
|
||||
response = Response()
|
||||
try:
|
||||
result = f(*args, **kwargs)
|
||||
except TypeError as e:
|
||||
logger.exception(e)
|
||||
result = Response(errors=[str(e)])
|
||||
|
||||
if result and isinstance(result, Response):
|
||||
result.errors = (
|
||||
|
|
Loading…
Reference in a new issue