From 92817e147de81864bf8861e86643536c62f683a1 Mon Sep 17 00:00:00 2001 From: shubhamgupta2956 Date: Fri, 20 Dec 2019 01:56:33 +0530 Subject: [PATCH] webhooks: Remove TrelloWebhookException classes. This removes zerver/webhooks/trello/view/exceptions.py, which contained legacy Trello webhook exception related classes. We replace them with UnexpectedWebhookEventType, which results in our standard exception handling for unknown event types running (avoiding too-high priority error logging). Fixes #13467. --- zerver/webhooks/trello/view/__init__.py | 5 ++--- zerver/webhooks/trello/view/board_actions.py | 4 ++-- zerver/webhooks/trello/view/card_actions.py | 4 ++-- zerver/webhooks/trello/view/exceptions.py | 11 ----------- 4 files changed, 6 insertions(+), 18 deletions(-) delete mode 100644 zerver/webhooks/trello/view/exceptions.py diff --git a/zerver/webhooks/trello/view/__init__.py b/zerver/webhooks/trello/view/__init__.py index a2d7cbdb08..71e1bdb8ce 100644 --- a/zerver/webhooks/trello/view/__init__.py +++ b/zerver/webhooks/trello/view/__init__.py @@ -12,7 +12,6 @@ from zerver.models import UserProfile from .card_actions import SUPPORTED_CARD_ACTIONS, \ IGNORED_CARD_ACTIONS, process_card_action from .board_actions import SUPPORTED_BOARD_ACTIONS, process_board_action -from .exceptions import UnsupportedAction @api_key_only_webhook_view('Trello') @return_success_on_head_request @@ -28,7 +27,7 @@ def api_trello_webhook(request: HttpRequest, return json_success() else: subject, body = message - except UnsupportedAction: + except UnexpectedWebhookEventType: if action_type in IGNORED_CARD_ACTIONS: return json_success() @@ -43,4 +42,4 @@ def get_subject_and_body(payload: Mapping[str, Any], action_type: str) -> Option if action_type in SUPPORTED_BOARD_ACTIONS: return process_board_action(payload, action_type) - raise UnsupportedAction('{} is not supported'.format(action_type)) + raise UnexpectedWebhookEventType("Trello", '{} is not supported'.format(action_type)) diff --git a/zerver/webhooks/trello/view/board_actions.py b/zerver/webhooks/trello/view/board_actions.py index 8976fbf1c9..f17606127f 100644 --- a/zerver/webhooks/trello/view/board_actions.py +++ b/zerver/webhooks/trello/view/board_actions.py @@ -1,6 +1,6 @@ from typing import Any, Dict, Mapping, Optional, Tuple -from .exceptions import UnknownUpdateBoardAction +from zerver.lib.exceptions import UnexpectedWebhookEventType SUPPORTED_BOARD_ACTIONS = [ u'removeMemberFromBoard', @@ -39,7 +39,7 @@ def get_proper_action(payload: Mapping[str, Any], action_type: Optional[str]) -> return None elif data['old']['name']: return CHANGE_NAME - raise UnknownUpdateBoardAction() + raise UnexpectedWebhookEventType("Trello", action_type) return action_type def get_subject(payload: Mapping[str, Any]) -> str: diff --git a/zerver/webhooks/trello/view/card_actions.py b/zerver/webhooks/trello/view/card_actions.py index a3a4a46e5f..bf1819f528 100644 --- a/zerver/webhooks/trello/view/card_actions.py +++ b/zerver/webhooks/trello/view/card_actions.py @@ -1,6 +1,6 @@ from typing import Any, Dict, Mapping, Optional, Tuple -from .exceptions import UnknownUpdateCardAction +from zerver.lib.exceptions import UnexpectedWebhookEventType SUPPORTED_CARD_ACTIONS = [ u'updateCard', @@ -104,7 +104,7 @@ def get_proper_action(payload: Mapping[str, Any], action_type: str) -> Optional[ # within a single list if old_data.get('pos'): return None - raise UnknownUpdateCardAction() + raise UnexpectedWebhookEventType("Trello", action_type) return action_type diff --git a/zerver/webhooks/trello/view/exceptions.py b/zerver/webhooks/trello/view/exceptions.py deleted file mode 100644 index 0dfa07de10..0000000000 --- a/zerver/webhooks/trello/view/exceptions.py +++ /dev/null @@ -1,11 +0,0 @@ -class TrelloWebhookException(Exception): - pass - -class UnsupportedAction(TrelloWebhookException): - pass - -class UnknownUpdateCardAction(TrelloWebhookException): - pass - -class UnknownUpdateBoardAction(TrelloWebhookException): - pass