1
Fork 0
mirror of https://github.com/Steffo99/greed.git synced 2024-11-21 21:44:19 +00:00

🧹 Clarify returns in catch_telegram_errors (closes #169)

This commit is contained in:
Steffo 2022-03-16 16:19:08 +01:00
parent dd7a45c581
commit 32bd6f6d84
Signed by: steffo
GPG key ID: 6965406171929D01

View file

@ -22,34 +22,39 @@ def factory(cfg: nuconfig.NuConfig):
# Bot was blocked by the user # Bot was blocked by the user
except telegram.error.Unauthorized: except telegram.error.Unauthorized:
log.debug(f"Unauthorized to call {func.__name__}(), skipping.") log.debug(f"Unauthorized to call {func.__name__}(), skipping.")
break return None
# Telegram API didn't answer in time # Telegram API didn't answer in time
except telegram.error.TimedOut: except telegram.error.TimedOut:
log.warning(f"Timed out while calling {func.__name__}()," log.warning(f"Timed out while calling {func.__name__}(),"
f" retrying in {cfg['Telegram']['timed_out_pause']} secs...") f" retrying in {cfg['Telegram']['timed_out_pause']} secs...")
time.sleep(cfg["Telegram"]["timed_out_pause"]) time.sleep(cfg["Telegram"]["timed_out_pause"])
continue
# Telegram is not reachable # Telegram is not reachable
except telegram.error.NetworkError as error: except telegram.error.NetworkError as error:
log.error(f"Network error while calling {func.__name__}()," log.error(f"Network error while calling {func.__name__}(),"
f" retrying in {cfg['Telegram']['error_pause']} secs...\n" f" retrying in {cfg['Telegram']['error_pause']} secs...\n"
f"Full error: {error.message}") f"Full error: {error.message}")
time.sleep(cfg["Telegram"]["error_pause"]) time.sleep(cfg["Telegram"]["error_pause"])
continue
# Unknown error # Unknown error
except telegram.error.TelegramError as error: except telegram.error.TelegramError as error:
if error.message.lower() in ["bad gateway", "invalid server response"]: if error.message.lower() in ["bad gateway", "invalid server response"]:
log.warning(f"Bad Gateway while calling {func.__name__}()," log.warning(f"Bad Gateway while calling {func.__name__}(),"
f" retrying in {cfg['Telegram']['error_pause']} secs...") f" retrying in {cfg['Telegram']['error_pause']} secs...")
time.sleep(cfg["Telegram"]["error_pause"]) time.sleep(cfg["Telegram"]["error_pause"])
continue
elif error.message.lower() == "timed out": elif error.message.lower() == "timed out":
log.warning(f"Timed out while calling {func.__name__}()," log.warning(f"Timed out while calling {func.__name__}(),"
f" retrying in {cfg['Telegram']['timed_out_pause']} secs...") f" retrying in {cfg['Telegram']['timed_out_pause']} secs...")
time.sleep(cfg["Telegram"]["timed_out_pause"]) time.sleep(cfg["Telegram"]["timed_out_pause"])
continue
else: else:
log.error(f"Telegram error while calling {func.__name__}()," log.error(f"Telegram error while calling {func.__name__}(),"
f" retrying in {cfg['Telegram']['error_pause']} secs...\n" f" retrying in {cfg['Telegram']['error_pause']} secs...\n"
f"Full error: {error.message}") f"Full error: {error.message}")
traceback.print_exception(*sys.exc_info()) traceback.print_exception(*sys.exc_info())
time.sleep(cfg["Telegram"]["error_pause"]) time.sleep(cfg["Telegram"]["error_pause"])
continue
return result_func return result_func