Skip to content

Commit

Permalink
feat: Added a better error page for the case of a client/server side …
Browse files Browse the repository at this point in the history
…error
  • Loading branch information
FleetAdmiralJakob committed Jan 12, 2024
1 parent 5ce22a6 commit 6cfbd27
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Binary file added apps/web/src/assets/error-page-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions apps/web/src/pages/_error/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { NextPage, NextPageContext } from "next";
import Head from "next/head";
import Image from "next/image";

import errorImage from "~/assets/error-page-image.png";

interface ErrorProps {
statusCode: number | undefined;
}

const Error: NextPage<ErrorProps> = ({ statusCode }) => {
return (
<>
<Head>
<title>Weather.io - Error</title>
</Head>
<div className="flex h-screen w-full flex-col items-center justify-center">
<Image src={errorImage} alt="Error" />
<p className="text-3xl font-bold">Error: We are sorry</p>
<p>
{statusCode
? `An error ${statusCode} occurred on server`
: "An error occurred on client"}
</p>
</div>
</>
);
};

Error.getInitialProps = async ({
res,
err,
}: NextPageContext): Promise<ErrorProps> => {
const statusCode = res ? res.statusCode : err ? err.statusCode : 404;
return { statusCode };
};

export default Error;

1 comment on commit 6cfbd27

@vercel
Copy link

@vercel vercel bot commented on 6cfbd27 Jan 12, 2024

Choose a reason for hiding this comment

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

Please sign in to comment.