Unverified Commit 73303a71 authored by Luis Alvarez D's avatar Luis Alvarez D Committed by GitHub

[Examples] Fix with-sentry (#15694)

parent dcb69ee9
import NextErrorComponent from 'next/error' import NextErrorComponent from 'next/error'
import * as Sentry from '@sentry/node' import * as Sentry from '@sentry/node'
const MyError = async ({ statusCode, hasGetInitialPropsRun, err }) => { const MyError = ({ statusCode, hasGetInitialPropsRun, err }) => {
if (!hasGetInitialPropsRun && err) { if (!hasGetInitialPropsRun && err) {
// getInitialProps is not called in case of // getInitialProps is not called in case of
// https://github.com/vercel/next.js/issues/8592. As a workaround, we pass // https://github.com/vercel/next.js/issues/8592. As a workaround, we pass
// err via _app.js so it can be captured // err via _app.js so it can be captured
Sentry.captureException(err) Sentry.captureException(err)
// flush is needed after calling captureException to send server side errors to Sentry, otherwise the serverless function will exit before it's sent
await Sentry.flush(2000)
} }
return <NextErrorComponent statusCode={statusCode} /> return <NextErrorComponent statusCode={statusCode} />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment