NextJS renders the custom error page (_error.jsx) when there is client-side UI error.
Is it possible to get information on the error inside the custom error page?
I'm using a custom App:
// pages/_app.jsx
import App from 'next/app'
function CustomApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
CustomApp.getInitialProps = async (props) => {
{ Component, ctx } = props
const initProps = await Component.getInitialProps(ctx);
return { pageProps: initProps }
}
export default CustomApp
and I have a page which triggers an error
// pages/throw_error.jsx
function ThrowErrorPage() {
throw new Error("client-side error")
...
}
export default ThrowError
and a custom error page
// pages/_error.jsx
function Error(props) {
// Expecting error from the UI
const { err } = props;
return (
<div>{err.message}</div>
)
}
Error.getInitialProps = async (props) => {
const { err } = props;
const statusCode = res ? res.statusCode : err ? err.statusCode : 404;
return { err, statusCode };
}
export default Error
I was expecting err to be passed from the UI to _error.jsx. Am I missing something?