Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

379
Vistas
NextJS custom _error page can't catch error details for server side errors in the production build

I am trying to catch NextJS serverside errors and flush the error messages to the sentry.

It is flushing messages without error details.

Here is the getServerSideProps error that I use try-catch block to catch an error in a nextjs page.

export const getServerSideProps: GetServerSideProps = async ({ locale }) => {
    try {
        throw new Error(`Server side error has been occured`)
        return {
            props: {
// SSR props
            }
        }
    } catch (error) {
        throw error
    }
    return { props: {} }
}

Here is the _error.tsx page implementation:

    import * as Sentry from "@sentry/nextjs"
    import NextErrorComponent, {ErrorProps as NextErrorProps} from "next/error"
    import {NextPageContext} from "next"
    // import envs from 'helpers/envs';
    
    export type ErrorPageProps = {
        err: Error
        statusCode: number
    }
    
    export type ErrorProps = {
        isReadyToRender: boolean
    } & NextErrorProps
    
    const ErrorPage = (props: ErrorPageProps): JSX.Element => {
        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 (
            <p>
                {statusCode ? `An error ${statusCode} occurred on server` : "An error occurred on client"}
            </p>
        )
    }
    
    ErrorPage.getInitialProps = async (props: NextPageContext): Promise<ErrorProps> => {
        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

How can I get error details from SSR and send to the sentry?

Any help will be appreciated.

Thanks

about 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda