-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added a better error page for the case of a client/server side …
…error
- Loading branch information
1 parent
5ce22a6
commit 6cfbd27
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
6cfbd27
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
weather-app – ./
weather-app-git-master-creative-programming-group.vercel.app
weather-app-swart-eight.vercel.app
weather-app-creative-programming-group.vercel.app
weatherio1.vercel.app
weather.roessner.tech