I have very basic setup, of getServerSideProps with Sentry error logging in Production on Vercel
export const getServerSideProps = async () => {
// some api call
if(error) {
throw new Error("Something went wrong")
}
return {
props: {
data
}
};
};
_error.js
looks like this
import * as Sentry from '@sentry/nextjs'
import { NextPageContext } from 'next'
import NextErrorComponent, { ErrorProps as NextErrorProps } from 'next/error'
const CustomErrorComponent = (props: NextErrorProps) => {
return <NextErrorComponent statusCode={props.statusCode} />
}
CustomErrorComponent.getInitialProps = async (contextData: NextPageContext) => {
await Sentry.captureUnderscoreErrorException(contextData)
console.log(contextData.res?.statusCode) // this shows as 404
console.log(contextData.err?.statusCode) // this as undefined
return NextErrorComponent.getInitialProps(contextData)
}
export default CustomErrorComponent
Please note if I run the same Prod build on my local machine I correctly see a 500: 'Internal Server Error'
but on Vercel I see this as 404: 'This page could not be found'
How can I show this as 500 error on Vercel ?