@@ -30,7 +30,11 @@ def __init__(self, webhook_url: str) -> None:
30
30
31
31
32
32
@retry_with_backoff (
33
- max_attempts = 8 , min_wait = 1 , max_wait = 128 , exceptions = (requests .exceptions .RequestException ,)
33
+ max_attempts = 8 ,
34
+ min_wait = 1 ,
35
+ max_wait = 128 ,
36
+ exceptions = (requests .exceptions .RequestException ,),
37
+ reraise = True ,
34
38
)
35
39
def _send_message (self , payload : Dict ) -> bool :
36
40
"""
@@ -40,37 +44,28 @@ def _send_message(self, payload: Dict) -> bool:
40
44
payload: The message payload to send
41
45
42
46
Returns:
43
- bool: True if message was sent successfully, False otherwise
47
+ bool: True if message was sent successfully.
48
+ Raises:
49
+ requests.exceptions.RequestException: If the request fails after all retries.
44
50
"""
45
51
# Get the message type from the payload
46
52
message_type = payload .get ("text" , "Unknown" )
47
53
48
54
# Log the message type
49
55
logger .info (f"Sending Slack notification: { message_type } " )
50
56
51
- try :
52
- response = requests .post (
53
- self .webhook_url ,
54
- json = payload ,
55
- timeout = self .timeout ,
56
- headers = {"Content-Type" : "application/json" },
57
- )
58
-
59
- # If the message is sent successfully, return True
60
- if response .status_code == 200 :
61
- logger .info ("Slack notification sent successfully" )
62
- return True
63
- else :
64
- # log message failure
65
- logger .warning (f"Slack notification failed: { response .status_code } " )
66
- # Raise an exception to trigger retry
67
- response .raise_for_status ()
68
- return False
69
-
70
- # If there is an error when trying to send the message, log the error and re-raise
71
- except requests .exceptions .RequestException as e :
72
- logger .warning (f"Slack notification failed: { str (e )} " )
73
- raise
57
+ response = requests .post (
58
+ self .webhook_url ,
59
+ json = payload ,
60
+ timeout = self .timeout ,
61
+ headers = {"Content-Type" : "application/json" },
62
+ )
63
+ # Raise an exception for 4xx/5xx responses
64
+ response .raise_for_status ()
65
+
66
+ # If the message is sent successfully, return True
67
+ logger .info ("Slack notification sent successfully" )
68
+ return True
74
69
75
70
76
71
def _create_payload (self , text : str , fields : List [Dict ], color : str = "good" ) -> Dict :
0 commit comments