forked from platypush/platypush
Fabio Manganiello
36fdcf6963
- Refactored the logic for executing a request and wrapping the response common to procedures, crons and event hook decorators into platypush.common.exec_wrapper - Added mock getvalue() method to Logger to prevent PyCharm failures in the tests when sys.stdout is redirected to the Logger object
18 lines
368 B
Python
18 lines
368 B
Python
import logging
|
|
|
|
logger = logging.getLogger('platypush')
|
|
|
|
|
|
def exec_wrapper(f, *args, **kwargs):
|
|
from platypush import Response
|
|
|
|
try:
|
|
ret = f(*args, **kwargs)
|
|
if isinstance(ret, Response):
|
|
return ret
|
|
|
|
return Response(output=ret)
|
|
except Exception as e:
|
|
logger.exception(e)
|
|
return Response(errors=[str(e)])
|