taslim19
commited on
Commit
·
13e24c7
1
Parent(s):
8fd3066
Improve whois.py error handling for API response
Browse files
DragMusic/plugins/games/whois.py
CHANGED
@@ -23,15 +23,17 @@ async def whois_character(client, message):
|
|
23 |
response = requests.post(API_URL, json=data, timeout=15)
|
24 |
response.raise_for_status()
|
25 |
result = response.json()
|
26 |
-
if result.get("status"):
|
27 |
reply_text = (
|
28 |
f"Name: {result['name']}\n"
|
29 |
f"Prefix: {result['prefix']}\n"
|
30 |
f"Bot: [{result['bot_name']}](https://t.me/{result['bot_name']}) (`{result['bot_id']}`)"
|
31 |
)
|
|
|
|
|
32 |
else:
|
33 |
-
reply_text = "
|
34 |
except Exception as e:
|
35 |
-
reply_text = f"API error: {e}"
|
36 |
|
37 |
await message.reply(reply_text)
|
|
|
23 |
response = requests.post(API_URL, json=data, timeout=15)
|
24 |
response.raise_for_status()
|
25 |
result = response.json()
|
26 |
+
if result.get("status") and all(k in result for k in ("name", "prefix", "bot_id", "bot_name")):
|
27 |
reply_text = (
|
28 |
f"Name: {result['name']}\n"
|
29 |
f"Prefix: {result['prefix']}\n"
|
30 |
f"Bot: [{result['bot_name']}](https://t.me/{result['bot_name']}) (`{result['bot_id']}`)"
|
31 |
)
|
32 |
+
elif not result.get("status"):
|
33 |
+
reply_text = f"No character found. (API status: {result.get('status')})"
|
34 |
else:
|
35 |
+
reply_text = f"API returned unexpected data: {result}"
|
36 |
except Exception as e:
|
37 |
+
reply_text = f"API error: {e}\nRaw response: {response.text if 'response' in locals() else 'No response'}"
|
38 |
|
39 |
await message.reply(reply_text)
|