title: NextJS custom _error page can't catch error details for server side errors in the production build
body: <p>I am trying to catch NextJS serverside errors and flush the error messages to the sentry.</p>
  <p>It is flushing messages without error details.</p>
  <p>Here is the <code>getServerSideProps</code> error that I use try-catch block to catch an error in a nextjs page.</p>
  <pre><code>export const getServerSideProps: GetServerSideProps = async ({ locale }) =&gt; {
      try {
          throw new Error(`Server side error has been occured`)
          return {
              props: {
  // SSR props
              }
          }
      } catch (error) {
          throw error
      }
      return { props: {} }
  }
  </code></pre>
  <p>Here is the <code>_error.tsx</code> page implementation:</p>
  <pre><code>    import * as Sentry from &quot;@sentry/nextjs&quot;
      import NextErrorComponent, {ErrorProps as NextErrorProps} from &quot;next/error&quot;
      import {NextPageContext} from &quot;next&quot;
      // import envs from 'helpers/envs';
      
      export type ErrorPageProps = {
          err: Error
          statusCode: number
      }
      
      export type ErrorProps = {
          isReadyToRender: boolean
      } &amp; NextErrorProps
      
      const ErrorPage = (props: ErrorPageProps): JSX.Element =&gt; {
          const {statusCode, err} = props
          // eslint-disable-next-line no-debugger
  
          // the problem is in here. err comes as undefined.
          if (err) {
              Sentry.captureException(err)
          }
      
          return (
              &lt;p&gt;
                  {statusCode ? `An error ${statusCode} occurred on server` : &quot;An error occurred on client&quot;}
              &lt;/p&gt;
          )
      }
      
      ErrorPage.getInitialProps = async (props: NextPageContext): Promise&lt;ErrorProps&gt; =&gt; {
          const {res, err, asPath} = props
          console.log(err)
      
          const errorInitialProps: ErrorProps = (await NextErrorComponent.getInitialProps({
              res,
              err
          } as NextPageContext)) as ErrorProps
      
          errorInitialProps.isReadyToRender = true
      
          if (res?.statusCode === 404) {
              return {statusCode: 404, isReadyToRender: true}
          }
      
          if (err) {
              Sentry.captureException(err)
              await Sentry.flush(2000)
              return errorInitialProps
          }
      
          Sentry.captureException(new Error(`_error.js getInitialProps missing data at path: ${asPath}`))
          await Sentry.flush(2000)
      
          return errorInitialProps
      }
      
      export default ErrorPage
  
  </code></pre>
  <p>How can I get error details from SSR and send to the sentry?</p>
  <p>Any help will be appreciated.</p>
  <p>Thanks</p>