I have a custom _error.tsx page in in my nextjs project to show 500 errors and to log the errors to Sentry. It works locally when I run the project in production mode with next build + next start, but whenever I deploy the app to Vercel I get a generic "EDGE_FUNCTION_INVOCATION_FAILED" error page whenever the app encounters 500 errors - effectively bypassing my custom error page:

In above case the an error was thrown in middleware.ts.
My custom _error.tsx page:
import { type GetServerSideProps } from 'next'function Error({ statusCode }) { return <p>{statusCode ? `An error ${statusCode} occurred on server` : 'An error occurred on client'}</p>}export const getServerSideProps: GetServerSideProps = async (context) => { // Log to Sentry here return { props: { statusCode: context.res.statusCode }, }}export default ErrorHow can I get this error page to work in Vercel?