Skip to content

Commit

Permalink
add back error page
Browse files Browse the repository at this point in the history
  • Loading branch information
jonat75 committed Jan 11, 2024
1 parent 51bc84a commit 0f8307f
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/app/src/app/error/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Alert from "@codegouvfr/react-dsfr/Alert";
import { type NextServerPageProps } from "@common/utils/next";
import { CenteredContainer } from "@design-system";
import { notFound } from "next/navigation";

import { Footer } from "../Footer";
import { Header } from "../Header";

const controlledErrors: Record<string, string | { message: string; source: string }> = {
AccessDenied: {
source: "login",
message: "Vous n'êtes pas staff.",
},
};

const ControlledErrorPage = ({ searchParams }: NextServerPageProps<never, "error" | "source">) => {
const error = controlledErrors[`${searchParams.error}`];
const source = `${searchParams.source}`;

if (!error) {
notFound();
}

const errorMessage = typeof error === "object" ? (source == error.source ? error.message : notFound()) : error;

return (
<>
<Header />
<main role="main" id="content" className="grow">
<CenteredContainer py="6w">
<Alert title="Erreur" severity="error" description={errorMessage} />
</CenteredContainer>
</main>
<Footer type="public" />
</>
);
};

export default ControlledErrorPage;

0 comments on commit 0f8307f

Please sign in to comment.