-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(error): fix incorrect 'view on IMDb' link on error page
the error was due to a faulty logic. 'useRouter' was being used to detect pathname, which doesn't keep original url on 404 page. this commit fixes that. this commit also makes it easy to go to IMDb by adding a clear link on error page. closes #50
- Loading branch information
Showing
9 changed files
with
94 additions
and
69 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
export type AppError = { | ||
message: string; | ||
statusCode: number; | ||
stack?: any; | ||
}; | ||
import { AppError as AppErrorClass } from 'src/utils/helpers'; | ||
|
||
export type AppError = Omit<InstanceType<typeof AppErrorClass>, 'name'>; |
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
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
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,25 @@ | ||
import type { GetServerSideProps, InferGetServerSidePropsType } from 'next'; | ||
import ErrorInfo from 'src/components/error/ErrorInfo'; | ||
|
||
const error = { | ||
statusCode: 404, | ||
message: 'Not found, sorry.', | ||
} as const; | ||
|
||
type Props = InferGetServerSidePropsType<typeof getServerSideProps>; | ||
|
||
const Error404 = ({ originalPath }: Props) => { | ||
return <ErrorInfo {...error} originalPath={originalPath} />; | ||
}; | ||
|
||
export default Error404; | ||
|
||
type Data = { originalPath: string }; | ||
type Params = { error: string[] }; | ||
|
||
export const getServerSideProps: GetServerSideProps<Data, Params> = async ctx => { | ||
ctx.res.statusCode = error.statusCode; | ||
ctx.res.statusMessage = error.message; | ||
|
||
return { props: { originalPath: ctx.resolvedUrl } }; | ||
}; |
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
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
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