Skip to content

Commit 41c3459

Browse files
committed
Added more detailed exception for teams webhook failure
1 parent 8c8c8b2 commit 41c3459

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

elementary/messages/messaging_integrations/teams_webhook.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
ONE_SECOND = 1
2828

2929

30+
class TeamsWebhookHttpError(MessagingIntegrationError):
31+
def __init__(self, response: requests.Response):
32+
self.status_code = response.status_code
33+
self.response = response
34+
super().__init__(
35+
f"Failed to send message to Teams webhook: {response.status_code}"
36+
)
37+
38+
3039
def send_adaptive_card(webhook_url: str, card: dict) -> requests.Response:
3140
payload = {
3241
"type": "message",
@@ -88,6 +97,8 @@ def send_message(
8897
timestamp=datetime.utcnow(),
8998
message_format="adaptive_cards",
9099
)
100+
except requests.HTTPError as e:
101+
raise TeamsWebhookHttpError(e.response) from e
91102
except requests.RequestException as e:
92103
raise MessagingIntegrationError(
93104
f"An error occurred while posting message to Teams webhook: {str(e)}"

0 commit comments

Comments
 (0)