From 53ea246d89cc994a94a1d5611e49c2c800d0fef2 Mon Sep 17 00:00:00 2001 From: Stefan Natter Date: Wed, 30 Jun 2021 20:01:42 +0200 Subject: [PATCH 1/2] feat: handle Promise.reject case of Sentry.flush --- examples/with-sentry/pages/_error.js | 21 +++++++++++---------- examples/with-sentry/pages/api/test4.js | 11 ++++++++--- examples/with-sentry/pages/ssr/test4.js | 10 +++++++--- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/examples/with-sentry/pages/_error.js b/examples/with-sentry/pages/_error.js index 003b2c873a255..11daab4ec2509 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) { + console.log(err) } - // 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..708dfd139b82b 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) { + console.log(err) + } } - // 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..429a7a1d9be31 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) { + console.log(err) + } } return { props: {} } From 27879dc2f9469a6881c20f9f0c03eb8e75d39759 Mon Sep 17 00:00:00 2001 From: Stefan Natter Date: Wed, 30 Jun 2021 20:49:42 +0200 Subject: [PATCH 2/2] fixup! remove console.log --- examples/with-sentry/pages/_error.js | 2 +- examples/with-sentry/pages/api/test4.js | 2 +- examples/with-sentry/pages/ssr/test4.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/with-sentry/pages/_error.js b/examples/with-sentry/pages/_error.js index 11daab4ec2509..333d0497d2a67 100644 --- a/examples/with-sentry/pages/_error.js +++ b/examples/with-sentry/pages/_error.js @@ -53,7 +53,7 @@ MyError.getInitialProps = async ({ res, err, asPath }) => { // https://vercel.com/docs/platform/limits#streaming-responses await Sentry.flush(2000) } catch (err) { - console.log(err) + // no-empty } return errorInitialProps diff --git a/examples/with-sentry/pages/api/test4.js b/examples/with-sentry/pages/api/test4.js index 708dfd139b82b..a00ddf7b9d62d 100644 --- a/examples/with-sentry/pages/api/test4.js +++ b/examples/with-sentry/pages/api/test4.js @@ -11,7 +11,7 @@ async function handler(req, res) { // https://vercel.com/docs/platform/limits#streaming-responses await Sentry.flush(2000) } catch (err) { - console.log(err) + // no-empty } } diff --git a/examples/with-sentry/pages/ssr/test4.js b/examples/with-sentry/pages/ssr/test4.js index 429a7a1d9be31..363f9208e77ff 100644 --- a/examples/with-sentry/pages/ssr/test4.js +++ b/examples/with-sentry/pages/ssr/test4.js @@ -13,7 +13,7 @@ export async function getServerSideProps() { // https://vercel.com/docs/platform/limits#streaming-responses await Sentry.flush(2000) } catch (err) { - console.log(err) + // no-empty } }