diff --git a/src/app/api/data/[facultyId]/route.ts b/src/app/api/data/[facultyId]/route.ts index 9133bf0..9f1e967 100644 --- a/src/app/api/data/[facultyId]/route.ts +++ b/src/app/api/data/[facultyId]/route.ts @@ -34,7 +34,9 @@ export async function GET( } catch (error) { // eslint-disable-next-line no-console console.error(error); - return new Response("Internal Server Error", { status: 500 }); + + const errorUrl = new URL(`/error-page?message=${encodeURIComponent(error.message)}`, _request.url); + return NextResponse.redirect(errorUrl, 302); } } diff --git a/src/pages/error-page.tsx b/src/pages/error-page.tsx new file mode 100644 index 0000000..cd8ba6c --- /dev/null +++ b/src/pages/error-page.tsx @@ -0,0 +1,39 @@ +import { useRouter } from 'next/router'; +import { useEffect, useState } from 'react'; + +const ErrorPage = () => { + const router = useRouter(); + const [errorMessage, setErrorMessage] = useState(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 ( +
+

Wystąpił błąd

+ {(errorMessage !== null) ? ( +

{errorMessage}

+ ) : ( +

Nie udało się załadować szczegółów błędu.

+ )} + +
+ ); +}; + +export default ErrorPage;