Skip to content

Commit

Permalink
feat: add error page
Browse files Browse the repository at this point in the history
  • Loading branch information
unewMe authored and simon-the-shark committed Sep 10, 2024
1 parent 81b5fc2 commit c677186
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/app/api/data/[facultyId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ export async function GET(
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
return new Response(`Internal Server Error ${error}`, { status: 200 });

const errorUrl = new URL(`/error-page?message=${encodeURIComponent(error.message)}`, _request.url);

Check failure on line 38 in src/app/api/data/[facultyId]/route.ts

View workflow job for this annotation

GitHub Actions / lint

'error' is of type 'unknown'.
return NextResponse.redirect(errorUrl, 302);
}
}

Expand Down
39 changes: 39 additions & 0 deletions src/pages/error-page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useRouter } from 'next/router';
import { useEffect, useState } from 'react';

const ErrorPage = () => {
const router = useRouter();
const [errorMessage, setErrorMessage] = useState<string | null>(null);

useEffect(() => {
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (router.query.message) {
setErrorMessage(decodeURIComponent(router.query.message as string));
}
}, [router.query]);

return (
<div style={{ padding: '20px', textAlign: 'center' }}>
<h1>Wystąpił błąd</h1>
{(errorMessage !== null) ? (
<p>{errorMessage}</p>
) : (
<p>Nie udało się załadować szczegółów błędu.</p>
)}
<button
// eslint-disable-next-line @typescript-eslint/no-misused-promises
onClick={() => router.push('/')}
style={{
padding: '10px 20px',
fontSize: '16px',
cursor: 'pointer',
marginTop: '20px',
}}
>
Powrót na stronę główną
</button>
</div>
);
};

export default ErrorPage;

0 comments on commit c677186

Please sign in to comment.