1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

fix error logs

This commit is contained in:
Steffo 2017-03-26 13:26:01 +02:00
parent e61d675693
commit 9b332e4a3b

View file

@ -139,12 +139,13 @@ class Bot:
# Send the request to the Telegram API
token = self.token
async with session.request("GET", f"https://api.telegram.org/bot{token}/{endpoint}", params=params) as response:
# Check for errors in the request
if response.status != 200:
error = await response.text()
raise TelegramAPIError(f"Request returned {response.status} {response.reason}\n{error}")
# Parse the json data as soon it's ready
data = await response.json()
# Check for errors in the request
if "description" in data:
error = data["description"]
if response.status != 200:
raise TelegramAPIError(f"Request returned {response.status} {response.reason}\n{}")
# Check for errors in the response
if not data["ok"]:
error = data["description"]
@ -230,7 +231,11 @@ class Chat:
# TODO: This could give problems if a class inherits Bot
if not isinstance(bot, Bot):
raise TypeError("bot is not an instance of Bot.")
await bot.api_request("sendMessage", text=text, chat_id=self.chat_id, **params)
# Catch TelegramAPI exceptions
try:
await bot.api_request("sendMessage", text=text, chat_id=self.chat_id, **params)
except TelegramAPIError as e:
print(f"[Telegram] sendMessage failed: {e.text}")
class User: