diff --git a/examples/with-sentry/pages/_error.js b/examples/with-sentry/pages/_error.js index 003b2c873a255..333d0497d2a67 100644 --- a/examples/with-sentry/pages/_error.js +++ b/examples/with-sentry/pages/_error.js @@ -39,22 +39,23 @@ MyError.getInitialProps = async ({ res, err, asPath }) => { if (err) { Sentry.captureException(err) + } else { + // If this point is reached, getInitialProps was called without any + // information about what the error might be. This is unexpected and may + // indicate a bug introduced in Next.js, so record it in Sentry + Sentry.captureException( + new Error(`_error.js getInitialProps missing data at path: ${asPath}`) + ) + } + try { // Flushing before returning is necessary if deploying to Vercel, see // https://vercel.com/docs/platform/limits#streaming-responses await Sentry.flush(2000) - - return errorInitialProps + } catch (err) { + // no-empty } - // If this point is reached, getInitialProps was called without any - // information about what the error might be. This is unexpected and may - // indicate a bug introduced in Next.js, so record it in Sentry - Sentry.captureException( - new Error(`_error.js getInitialProps missing data at path: ${asPath}`) - ) - await Sentry.flush(2000) - return errorInitialProps } diff --git a/examples/with-sentry/pages/api/test4.js b/examples/with-sentry/pages/api/test4.js index f4724110c0e10..a00ddf7b9d62d 100644 --- a/examples/with-sentry/pages/api/test4.js +++ b/examples/with-sentry/pages/api/test4.js @@ -5,11 +5,16 @@ async function handler(req, res) { throw new Error('API Test 4') } catch (error) { Sentry.captureException(error) + + try { + // Flushing before returning is necessary if deploying to Vercel, see + // https://vercel.com/docs/platform/limits#streaming-responses + await Sentry.flush(2000) + } catch (err) { + // no-empty + } } - // Flushing before returning is necessary if deploying to Vercel, see - // https://vercel.com/docs/platform/limits#streaming-responses - await Sentry.flush(2000) res.status(200).json({ name: 'John Doe' }) } diff --git a/examples/with-sentry/pages/ssr/test4.js b/examples/with-sentry/pages/ssr/test4.js index 737339f85dd3d..363f9208e77ff 100644 --- a/examples/with-sentry/pages/ssr/test4.js +++ b/examples/with-sentry/pages/ssr/test4.js @@ -8,9 +8,13 @@ export async function getServerSideProps() { } catch (error) { Sentry.captureException(error) - // Flushing before returning is necessary if deploying to Vercel, see - // https://vercel.com/docs/platform/limits#streaming-responses - await Sentry.flush(2000) + try { + // Flushing before returning is necessary if deploying to Vercel, see + // https://vercel.com/docs/platform/limits#streaming-responses + await Sentry.flush(2000) + } catch (err) { + // no-empty + } } return { props: {} }