@@ -69,14 +69,21 @@ def _notify(self, message="", **kwargs: dict):
69
69
raise ProviderException ("Message is required" )
70
70
71
71
def __send_message (url , body , headers , retries = 3 ):
72
- for _ in range (retries ):
72
+ for attempt in range (retries ):
73
73
try :
74
74
resp = requests .post (url , json = body , headers = headers )
75
75
if resp .status_code == http .HTTPStatus .OK :
76
76
return resp
77
+
78
+ self .logger .warning (f"Attempt { attempt + 1 } failed with status code { resp .status_code } " )
79
+
77
80
except requests .exceptions .RequestException as e :
78
- self .logger .error (f"Failed to send message to Google Chat: { e } " )
79
- time .sleep (1 )
81
+ self .logger .error (f"Attempt { attempt + 1 } failed: { e } " )
82
+
83
+ if attempt < retries - 1 :
84
+ time .sleep (1 )
85
+
86
+ raise requests .exceptions .RequestException (f"Failed to notify message after { retries } attempts" )
80
87
81
88
payload = {
82
89
"text" : message ,
@@ -85,11 +92,8 @@ def __send_message(url, body, headers, retries=3):
85
92
request_headers = {"Content-Type" : "application/json; charset=UTF-8" }
86
93
87
94
response = __send_message (webhook_url , body = payload , headers = request_headers )
88
-
89
- if not response .ok :
90
- raise ProviderException (
91
- f"Failed to notify message to Google Chat: { response .text } "
92
- )
95
+ if response .status_code != http .HTTPStatus .OK :
96
+ raise ProviderException (f"Failed to notify message to Google Chat: { response .text } " )
93
97
94
98
self .logger .debug ("Alert message sent to Google Chat successfully" )
95
99
return "Alert message sent to Google Chat successfully"
0 commit comments