aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRahiel Kasim <rahielkasim@gmail.com>2016-02-10 19:26:52 +0100
committerRahiel Kasim <rahielkasim@gmail.com>2016-02-10 19:26:52 +0100
commit05e0034ee24ae76a40f0734b86db790e093fa03e (patch)
tree54825a0250f89a8bfd0f26a3add5ba6b51c6a672
parent177f93c4aae6ae034ed7eb55e510bff5d571449d (diff)
simpler exception handling
-rw-r--r--bismillah.py14
1 files changed, 5 insertions, 9 deletions
diff --git a/bismillah.py b/bismillah.py
index 4553f3a..4967229 100644
--- a/bismillah.py
+++ b/bismillah.py
@@ -21,6 +21,7 @@ from time import sleep, time
import sys
import telegram
+from telegram.error import NetworkError, Unauthorized
from redis import StrictRedis
import ujson as json
@@ -70,15 +71,10 @@ def main():
while True:
try:
update_id = serve(bot, update_id, data)
- except telegram.TelegramError as e:
- if e.message in ("Bad Gateway", "Timed out") or (
- e.message.startswith("URLError") or
- e.message.startswith("HTTPException")):
- sleep(1)
- elif e.message == "Unauthorized":
- update_id += 1
- else:
- raise e
+ except NetworkError:
+ sleep(0.2)
+ except Unauthorized: # user has removed or blocked the bot
+ update_id += 1
def serve(bot, update_id, data):