Skip to content
This repository was archived by the owner on Sep 9, 2024. It is now read-only.

Commit dfd13b0

Browse files
committed
Raise error when domains cannot be found
1 parent b7f714c commit dfd13b0

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

_orangcbot/extensions/nonsense.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
from .converters import SubdomainNameConverter
1111

1212

13+
class DomainNotExistError(commands.CommandError):
14+
"""Error raised when domain cannot be found."""
15+
16+
1317
class LinkView(nextcord.ui.View):
1418
def __init__(self):
1519
super().__init__()
@@ -35,6 +39,8 @@ def __init__(self):
3539
async def request(*args, **kwargs):
3640
async with aiohttp.ClientSession() as session:
3741
async with session.request(*args, **kwargs) as ans:
42+
if ans.status == 404:
43+
raise DomainNotExistError("imagine")
3844
return await ans.json(content_type=None)
3945

4046

@@ -237,10 +243,14 @@ async def whois(
237243
label="Edit this subdomain?",
238244
)
239245
)
240-
data = await request(
241-
"GET",
242-
f"https://raw.githubusercontent.com/is-a-dev/register/main/domains/{domain}.json",
243-
)
246+
try:
247+
data = await request(
248+
"GET",
249+
f"https://raw.githubusercontent.com/is-a-dev/register/main/domains/{domain}.json",
250+
)
251+
except DomainNotExistError:
252+
await ctx.send("The domain queried cannot be found. Aborting.")
253+
return
244254
embed = nextcord.Embed(
245255
color=nextcord.Color.red(),
246256
title=f"Info about {domain}.is-a.dev",

0 commit comments

Comments
 (0)