Skip to content

Commit

Permalink
use modified whois API with better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
aelew committed Feb 6, 2024
1 parent 9efff18 commit 44fe62d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/app/(tools)/(domain)/whois/[domain]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ export default async function WhoisLookupResultPage({
}

const result = await getCachedWhoisLookup(domain);
if (!result) {
if (!result.success) {
if (result.error !== 'domain_not_found') {
// TODO: Add some kind of component that shows the error code
notFound();
}
return (
<>
<DomainHeader domain={domain} searchAgainForm={WhoisLookupForm} />
Expand Down
6 changes: 4 additions & 2 deletions src/lib/ip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ export async function getIPData(query: string) {
let result;
try {
result = await ky
.get(`https://api.aelew.dev/ip/${encodeURIComponent(query)}`)
.get(`https://api.aelew.dev/ip/${encodeURIComponent(query)}`, {
throwHttpErrors: false
})
.json<IPResult>();
} catch (err) {
} catch {
result = {
success: false,
error: 'internal_server_error'
Expand Down
16 changes: 13 additions & 3 deletions src/lib/whois.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export type ContactInfo = {
email?: string;
};

type WhoisResult = {
type WhoisSuccessResult = {
success: true;
domain: {
id: string;
domain: string;
Expand Down Expand Up @@ -46,14 +47,23 @@ type WhoisResult = {
billing?: ContactInfo;
};

export type WhoisErrorResult = { success: false; error: string };

export type WhoisResult = WhoisSuccessResult | WhoisErrorResult;

export async function getWhoisData(query: string) {
let result;
try {
result = await ky
.get(`https://who-dat.as93.net/${encodeURIComponent(query)}`)
.get(`https://api.aelew.dev/whois/${encodeURIComponent(query)}`, {
throwHttpErrors: false
})
.json<WhoisResult>();
} catch {
result = null;
result = {
success: false,
error: 'internal_server_error'
} as const;
}
return result;
}

0 comments on commit 44fe62d

Please sign in to comment.