Skip to content

Commit

Permalink
Improve error pages 👌
Browse files Browse the repository at this point in the history
  • Loading branch information
wotschofsky committed Oct 2, 2023
1 parent dee4ac6 commit b4c26c7
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 15 deletions.
48 changes: 43 additions & 5 deletions app/lookup/[domain]/certs/error.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,47 @@
'use client';

const CertsError = () => (
<div className="flex items-center justify-center">
<p className="my-8">An error occurred!</p>
</div>
);
import { Loader2 } from 'lucide-react';
import { revalidatePath } from 'next/cache';
import { useParams } from 'next/navigation';
import { type FC, useCallback, useEffect, useState } from 'react';

import { Button } from '@/components/ui/button';

type CertsErrorProps = {
error: Error & { digest?: string };
reset: () => void;
};

const CertsError: FC<CertsErrorProps> = ({ error }) => {
const [isLoading, setLoading] = useState(false);
const { domain } = useParams() as { domain: string };

useEffect(() => {
console.error(error);
}, [error]);

const handleReset = useCallback(() => {
setLoading(true);
revalidatePath(`/lookup/${domain}/certs`);
}, [domain]);

return (
<div className="mt-12 flex flex-col items-center gap-2">
<h2>Something went wrong!</h2>
<p className="mt-2 text-center text-sm text-muted-foreground">
Digest: {error.digest}
</p>
<Button
className="mt-4"
onClick={handleReset}
disabled={isLoading}
variant="outline"
>
{isLoading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
Try again
</Button>
</div>
);
};

export default CertsError;
13 changes: 8 additions & 5 deletions app/lookup/[domain]/error.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
'use client';

import { Loader2 } from 'lucide-react';
import { revalidatePath } from 'next/cache';
import { useParams } from 'next/navigation';
import { type FC, useCallback, useEffect, useState } from 'react';

import { Button } from '@/components/ui/button';

type LookupDomainErrorProps = {
type DomainErrorProps = {
error: Error & { digest?: string };
reset: () => void;
};

const LookupDomainError: FC<LookupDomainErrorProps> = ({ error, reset }) => {
const DomainError: FC<DomainErrorProps> = ({ error }) => {
const [isLoading, setLoading] = useState(false);
const { domain } = useParams() as { domain: string };

useEffect(() => {
console.error(error);
}, [error]);

const handleReset = useCallback(() => {
setLoading(true);
reset();
}, [reset]);
revalidatePath(`/lookup/${domain}`);
}, [domain]);

return (
<div className="mt-12 flex flex-col items-center gap-2">
Expand All @@ -41,4 +44,4 @@ const LookupDomainError: FC<LookupDomainErrorProps> = ({ error, reset }) => {
);
};

export default LookupDomainError;
export default DomainError;
48 changes: 43 additions & 5 deletions app/lookup/[domain]/whois/error.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,47 @@
'use client';

const WhoisError = () => (
<div className="flex items-center justify-center">
<p className="my-8">An error occurred!</p>
</div>
);
import { Loader2 } from 'lucide-react';
import { revalidatePath } from 'next/cache';
import { useParams } from 'next/navigation';
import { type FC, useCallback, useEffect, useState } from 'react';

import { Button } from '@/components/ui/button';

type WhoisErrorProps = {
error: Error & { digest?: string };
reset: () => void;
};

const WhoisError: FC<WhoisErrorProps> = ({ error }) => {
const [isLoading, setLoading] = useState(false);
const { domain } = useParams() as { domain: string };

useEffect(() => {
console.error(error);
}, [error]);

const handleReset = useCallback(() => {
setLoading(true);
revalidatePath(`/lookup/${domain}/whois`);
}, [domain]);

return (
<div className="mt-12 flex flex-col items-center gap-2">
<h2>Something went wrong!</h2>
<p className="mt-2 text-center text-sm text-muted-foreground">
Digest: {error.digest}
</p>
<Button
className="mt-4"
onClick={handleReset}
disabled={isLoading}
variant="outline"
>
{isLoading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
Try again
</Button>
</div>
);
};

export default WhoisError;

1 comment on commit b4c26c7

@vercel
Copy link

@vercel vercel bot commented on b4c26c7 Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

domain-digger – ./

domain-digger-wotschofsky.vercel.app
domain-digger-git-main-wotschofsky.vercel.app
www.digger.tools
digger.tools

Please sign in to comment.