Skip to content

Commit e7a7af0

Browse files
committed
Added __validate_response
1 parent a2a2d05 commit e7a7af0

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

whatsapp_chatbot_python/bot.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import NoReturn, Optional
22

3-
from whatsapp_api_client_python.API import GreenApi
3+
from whatsapp_api_client_python.API import GreenApi, Response
44

55
from .manager.router import Router
66

@@ -29,8 +29,8 @@ def run_forever(self) -> Optional[NoReturn]:
2929
while True:
3030
try:
3131
response = self.api.receiving.receiveNotification()
32-
if response.error:
33-
raise GreenAPIError(response.error)
32+
33+
self.__validate_response(response)
3434

3535
if not response.data:
3636
continue
@@ -74,6 +74,15 @@ def _delete_notifications_at_startup(self) -> Optional[NoReturn]:
7474

7575
self.api.receiving.deleteNotification(response.data["receiptId"])
7676

77+
@staticmethod
78+
def __validate_response(response: Response) -> Optional[NoReturn]:
79+
if response.code != 200:
80+
if response.error:
81+
raise GreenAPIError(response.error)
82+
raise GreenAPIError(
83+
f"GreenAPI error occurred with status code {response.code}"
84+
)
85+
7786

7887
class GreenAPI(GreenApi):
7988
pass

0 commit comments

Comments
 (0)