forked from platypush/platypush
Catch all the exceptions in a plugin action wrapper.
The @action decorator should capture all the exceptions, log them and return them on `Response.errors`. This ensures that uncaught exceptions from plugin actions won't unwind out of control, and also that they are logged and treated consistently across all the integrations.
This commit is contained in:
parent
ac72b2f7a8
commit
2c93049ee5
1 changed files with 4 additions and 1 deletions
|
@ -32,7 +32,10 @@ def action(f: Callable[..., Any]) -> Callable[..., Response]:
|
||||||
response = Response()
|
response = Response()
|
||||||
try:
|
try:
|
||||||
result = f(*args, **kwargs)
|
result = f(*args, **kwargs)
|
||||||
except TypeError as e:
|
except Exception as e:
|
||||||
|
if isinstance(e, KeyboardInterrupt):
|
||||||
|
return response
|
||||||
|
|
||||||
_logger.exception(e)
|
_logger.exception(e)
|
||||||
result = Response(errors=[str(e)])
|
result = Response(errors=[str(e)])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue