Skip to content

Commit 3b5ea88

Browse files
committed
Fixed error handling
1 parent 7798166 commit 3b5ea88

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .bot import Bot, GreenAPI, GreenAPIBot, GreenAPIError
1+
from .bot import Bot, GreenAPI, GreenAPIBot, GreenAPIError, GreenAPIBotError
22
from .manager.handler import Notification
33
from .manager.state import BaseStates
44

@@ -7,6 +7,7 @@
77
"GreenAPI",
88
"GreenAPIBot",
99
"GreenAPIError",
10+
"GreenAPIBotError",
1011
"Notification",
1112
"BaseStates"
1213
]

whatsapp_chatbot_python/bot.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,13 @@ def run_forever(self) -> Optional[NoReturn]:
7979
self.api.receiving.deleteNotification(response["receiptId"])
8080
except KeyboardInterrupt:
8181
break
82-
except Exception as e:
83-
self.logger.log(logging.ERROR, f"An unexpected error occurred: {e}")
84-
time.sleep(5)
82+
except Exception as error:
83+
if self.raise_errors:
84+
raise GreenAPIBotError(error)
85+
self.logger.log(logging.ERROR, error)
86+
87+
time.sleep(5.0)
88+
8589
continue
8690

8791
self.api.session.headers["Connection"] = "close"
@@ -163,4 +167,14 @@ class GreenAPIBot(Bot):
163167
pass
164168

165169

166-
__all__ = ["Bot", "GreenAPI", "GreenAPIBot", "GreenAPIError"]
170+
class GreenAPIBotError(Exception):
171+
pass
172+
173+
174+
__all__ = [
175+
"Bot",
176+
"GreenAPI",
177+
"GreenAPIBot",
178+
"GreenAPIError",
179+
"GreenAPIBotError"
180+
]

0 commit comments

Comments
 (0)