From aa66b81b7b94d4355843dbea424a73f92eb8ce0e Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 9 May 2020 01:47:12 +0200 Subject: [PATCH] Fixed webhook event management --- platypush/backend/http/app/routes/hook.py | 12 ++++++------ platypush/message/event/__init__.py | 3 ++- platypush/message/event/http/hook.py | 3 +-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/platypush/backend/http/app/routes/hook.py b/platypush/backend/http/app/routes/hook.py index e4e6954b..871d2a99 100644 --- a/platypush/backend/http/app/routes/hook.py +++ b/platypush/backend/http/app/routes/hook.py @@ -18,7 +18,7 @@ __routes__ = [ @hook.route('/hook/', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS']) @authenticate(skip_auth_methods=['session']) -def hook(hook_name): +def _hook(hook_name): """ Endpoint for custom webhooks """ event_args = { @@ -29,6 +29,7 @@ def hook(hook_name): } if event_args['data']: + # noinspection PyBroadException try: event_args['data'] = json.loads(event_args['data']) except: @@ -37,12 +38,11 @@ def hook(hook_name): event = WebhookEvent(**event_args) try: - response = send_message(event) - return Response(json.dumps({'status': 'ok', **event_args}), - mimetype='application/json') + send_message(event) + return Response(json.dumps({'status': 'ok', **event_args}), mimetype='application/json') except Exception as e: - logger().error('Error while dispatching webhook event {}: {}'. - format(event, str(e))) + logger().exception(e) + logger().error('Error while dispatching webhook event {}: {}'.format(event, str(e))) abort(500, str(e)) diff --git a/platypush/message/event/__init__.py b/platypush/message/event/__init__.py index 966e16e4..968db68f 100644 --- a/platypush/message/event/__init__.py +++ b/platypush/message/event/__init__.py @@ -40,7 +40,8 @@ class Event(Message): self.disable_web_clients_notification = disable_web_clients_notification for arg, value in self.args.items(): - self.__setattr__(arg, value) + if arg != 'args': + self.__setattr__(arg, value) @classmethod def build(cls, msg): diff --git a/platypush/message/event/http/hook.py b/platypush/message/event/http/hook.py index 645da843..1b843067 100644 --- a/platypush/message/event/http/hook.py +++ b/platypush/message/event/http/hook.py @@ -20,8 +20,7 @@ class WebhookEvent(Event): :type args: dict """ - super().__init__(hook=hook, method=method, data=data, - args=args or {}, *argv, **kwargs) + super().__init__(hook=hook, method=method, data=data, args=args or {}, *argv, **kwargs) # vim:sw=4:ts=4:et: