-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy path_error.tsx
42 lines (34 loc) · 1.3 KB
/
_error.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//@ts-nocheck
import NextErrorComponent from "next/error";
const ErrorPage = ({ statusCode, hasGetInitialPropsRun, err }) => {
return <NextErrorComponent statusCode={statusCode} />;
};
ErrorPage.getInitialProps = async ({ res, err, asPath }) => {
const errorInitialProps = await NextErrorComponent.getInitialProps({
res,
err,
});
// Workaround for https://github.com/vercel/next.js/issues/8592, mark when
// getInitialProps has run
errorInitialProps.hasGetInitialPropsRun = true;
// Running on the server, the response object (`res`) is available.
//
// Next.js will pass an err on the server if a page's data fetching methods
// threw or returned a Promise that rejected
//
// Running on the client (browser), Next.js will provide an err if:
//
// - a page's `getInitialProps` threw or returned a Promise that rejected
// - an exception was thrown somewhere in the React lifecycle (render,
// componentDidMount, etc) that was caught by Next.js's React Error
// Boundary. Read more about what types of exceptions are caught by Error
// Boundaries: https://reactjs.org/docs/error-boundaries.html
if (res?.statusCode === 404) {
return { statusCode: 404 };
}
if (err) {
return errorInitialProps;
}
return errorInitialProps;
};
export default ErrorPage;