@@ -85,31 +85,37 @@ def send_message(self, message="", title="", **kwargs):
8585
8686 _LOGGER .debug ("Sending notification .." )
8787
88- response = requests .post (
89- self ._resource ,
90- json = payload ,
91- timeout = 10
92- )
93-
94- _LOGGER .debug ("Checking result .." )
95-
96- if response .status_code == HTTPStatus .INTERNAL_SERVER_ERROR :
97- _LOGGER .exception ("Server error. Response %d: %s" , response .status_code , response .reason )
98- elif response .status_code == HTTPStatus .BAD_REQUEST :
99- _LOGGER .exception ("Client error (bad request). Response %d: %s" , response .status_code , response .reason )
100- elif response .status_code == HTTPStatus .NOT_FOUND :
101- _LOGGER .exception ("Server error (not found). Response %d: %s" , response .status_code , response .reason )
102- elif response .status_code == HTTPStatus .METHOD_NOT_ALLOWED :
103- _LOGGER .exception ("Server error (method not allowed). Response %d" , response .status_code )
104- elif response .status_code == HTTPStatus .REQUEST_TIMEOUT :
105- _LOGGER .exception ("Server error (request timeout). Response %d: %s" , response .status_code , response .reason )
106- elif response .status_code == HTTPStatus .NOT_IMPLEMENTED :
107- _LOGGER .exception ("Server error (not implemented). Response %d: %s" , response .status_code , response .reason )
108- elif response .status_code == HTTPStatus .SERVICE_UNAVAILABLE :
109- _LOGGER .exception ("Server error (service unavailable). Response %d" , response .status_code )
110- elif response .status_code == HTTPStatus .GATEWAY_TIMEOUT :
111- _LOGGER .exception ("Network error (gateway timeout). Response %d: %s" , response .status_code , response .reason )
112- elif response .status_code == HTTPStatus .OK :
113- _LOGGER .debug ("Success. Response %d: %s" , response .status_code , response .reason )
114- else :
115- _LOGGER .debug ("Unknown response %d: %s" , response .status_code , response .reason )
88+ try :
89+
90+ response = requests .post (
91+ self ._resource ,
92+ json = payload ,
93+ timeout = 10
94+ )
95+
96+ _LOGGER .debug ("Checking result .." )
97+
98+ if response .status_code == HTTPStatus .INTERNAL_SERVER_ERROR :
99+ _LOGGER .error ("Server error. Response %d: %s" , response .status_code , response .reason )
100+ elif response .status_code == HTTPStatus .BAD_REQUEST :
101+ _LOGGER .error ("Client error (bad request). Response %d: %s" , response .status_code , response .reason )
102+ elif response .status_code == HTTPStatus .NOT_FOUND :
103+ _LOGGER .debug ("Server error (not found). Response %d: %s" , response .status_code , response .reason )
104+ elif response .status_code == HTTPStatus .METHOD_NOT_ALLOWED :
105+ _LOGGER .error ("Server error (method not allowed). Response %d" , response .status_code )
106+ elif response .status_code == HTTPStatus .REQUEST_TIMEOUT :
107+ _LOGGER .debug ("Server error (request timeout). Response %d: %s" , response .status_code , response .reason )
108+ elif response .status_code == HTTPStatus .NOT_IMPLEMENTED :
109+ _LOGGER .error ("Server error (not implemented). Response %d: %s" , response .status_code , response .reason )
110+ elif response .status_code == HTTPStatus .SERVICE_UNAVAILABLE :
111+ _LOGGER .error ("Server error (service unavailable). Response %d" , response .status_code )
112+ elif response .status_code == HTTPStatus .GATEWAY_TIMEOUT :
113+ _LOGGER .error ("Network error (gateway timeout). Response %d: %s" , response .status_code , response .reason )
114+ elif response .status_code == HTTPStatus .OK :
115+ _LOGGER .debug ("Success. Response %d: %s" , response .status_code , response .reason )
116+ else :
117+ _LOGGER .debug ("Unknown response %d: %s" , response .status_code , response .reason )
118+
119+ except Exception as e :
120+ _LOGGER .debug ("Error sending message: %s" , e )
121+
0 commit comments