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:
parent
e61d675693
commit
9b332e4a3b
1 changed files with 10 additions and 5 deletions
13
telegram.py
13
telegram.py
|
@ -139,12 +139,13 @@ class Bot:
|
||||||
# Send the request to the Telegram API
|
# Send the request to the Telegram API
|
||||||
token = self.token
|
token = self.token
|
||||||
async with session.request("GET", f"https://api.telegram.org/bot{token}/{endpoint}", params=params) as response:
|
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
|
# Parse the json data as soon it's ready
|
||||||
data = await response.json()
|
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
|
# Check for errors in the response
|
||||||
if not data["ok"]:
|
if not data["ok"]:
|
||||||
error = data["description"]
|
error = data["description"]
|
||||||
|
@ -230,7 +231,11 @@ class Chat:
|
||||||
# TODO: This could give problems if a class inherits Bot
|
# TODO: This could give problems if a class inherits Bot
|
||||||
if not isinstance(bot, Bot):
|
if not isinstance(bot, Bot):
|
||||||
raise TypeError("bot is not an instance of Bot.")
|
raise TypeError("bot is not an instance of Bot.")
|
||||||
|
# Catch TelegramAPI exceptions
|
||||||
|
try:
|
||||||
await bot.api_request("sendMessage", text=text, chat_id=self.chat_id, **params)
|
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:
|
class User:
|
||||||
|
|
Loading…
Reference in a new issue