Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add console logs #51

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/app/api/data/[facultyId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
} 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);

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);
}
}

export type ApiProfileGet = ApiResponse<typeof GET>;

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

View workflow job for this annotation

GitHub Actions / lint

Type '(_request: Request, { params }: { params: { facultyId: string; }; }) => Promise<NextResponse<unknown>>' does not satisfy the constraint '(...args: unknown[]) => NextResponse<unknown> | Promise<NextResponse<unknown>>'.
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;
Loading