From f276419889c2cd494ddddcc48633f30752baf5f1 Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Tue, 27 Apr 2021 10:41:26 +0200 Subject: [PATCH 1/6] feat: Ref update next.js config --- .../javascript.nextjs.mdx | 16 ++++++++++- .../javascript.nextjs.mdx | 28 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/includes/getting-started-verify/javascript.nextjs.mdx diff --git a/src/includes/getting-started-config/javascript.nextjs.mdx b/src/includes/getting-started-config/javascript.nextjs.mdx index d9dfbe2262a16..730eb0697773f 100644 --- a/src/includes/getting-started-config/javascript.nextjs.mdx +++ b/src/includes/getting-started-config/javascript.nextjs.mdx @@ -14,4 +14,18 @@ See [manual configuration](/platforms/javascript/guides/nextjs/manual-setup/) fo To complete your configuration, add [options](/platforms/javascript/configuration/) to your two `Sentry.init()` calls (in `sentry.client.config.js` and `sentry.server.config.js`, respectively). In those two files you can also set context data - data about the [user](/platforms/javascript/enriching-events/identify-user/), for example, or [tags](/platforms/javascript/enriching-events/tags/), or even [arbitrary data](/platforms/javascript/enriching-events/context/) - which will be added to every event sent to Sentry. -Once you're set up, the SDK will automatically capture unhandled errors and promise rejections. You can also [manually capture errors](/platforms/javascript/guides/nextjs/usage). +Once you're set up, the SDK will automatically capture unhandled errors and promise rejections in your frontend. You can also [manually capture errors](/platforms/javascript/guides/nextjs/usage). + +To capture server / API route errors you need to wrap your handlers with a Sentry function like this: + +```JavaScript +// Next.js API route support: https://nextjs.org/docs/api-routes/introduction +import * as Sentry from '@sentry/nextjs'; + +const handler = async (req, res) => { + // throw new Error('API Test 4') + res.status(200).json({ name: 'John Doe' }) +} + +export default Sentry.withSentry(handler); +``` \ No newline at end of file diff --git a/src/includes/getting-started-verify/javascript.nextjs.mdx b/src/includes/getting-started-verify/javascript.nextjs.mdx new file mode 100644 index 0000000000000..2fd62ad614124 --- /dev/null +++ b/src/includes/getting-started-verify/javascript.nextjs.mdx @@ -0,0 +1,28 @@ +Add a button to a frontend component that throws an error: + +```javascript {filename:index.js} + +``` + +And throw an error in an API route: + +```javascript {filename:pages/api/hello.js} +// Next.js API route support: https://nextjs.org/docs/api-routes/introduction +import * as Sentry from '@sentry/nextjs'; + +const handler = async (req, res) => { + throw new Error('API throw error test') + res.status(200).json({ name: 'John Doe' }) +} + +export default Sentry.withSentry(handler); +``` + + +Errors triggered from within Browser DevTools are sandboxed, so will not trigger an error handler. Place the snippet directly in your code instead. + + From 795e317b852fc2a777da62f3dded69cb38baf145 Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Tue, 27 Apr 2021 10:45:59 +0200 Subject: [PATCH 2/6] fix: lang --- src/includes/getting-started-config/javascript.nextjs.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/includes/getting-started-config/javascript.nextjs.mdx b/src/includes/getting-started-config/javascript.nextjs.mdx index 730eb0697773f..1ff09d4ffd015 100644 --- a/src/includes/getting-started-config/javascript.nextjs.mdx +++ b/src/includes/getting-started-config/javascript.nextjs.mdx @@ -18,7 +18,7 @@ Once you're set up, the SDK will automatically capture unhandled errors and prom To capture server / API route errors you need to wrap your handlers with a Sentry function like this: -```JavaScript +```javascript // Next.js API route support: https://nextjs.org/docs/api-routes/introduction import * as Sentry from '@sentry/nextjs'; From 635b0b5bbe2b1f3a80f7f6d9a1cfd28f480e96f9 Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Tue, 27 Apr 2021 11:31:38 +0200 Subject: [PATCH 3/6] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kamil Ogórek --- src/includes/getting-started-config/javascript.nextjs.mdx | 6 +++--- src/includes/getting-started-verify/javascript.nextjs.mdx | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/includes/getting-started-config/javascript.nextjs.mdx b/src/includes/getting-started-config/javascript.nextjs.mdx index 1ff09d4ffd015..9ce8b91bfa21f 100644 --- a/src/includes/getting-started-config/javascript.nextjs.mdx +++ b/src/includes/getting-started-config/javascript.nextjs.mdx @@ -20,12 +20,12 @@ To capture server / API route errors you need to wrap your handlers with a Sentr ```javascript // Next.js API route support: https://nextjs.org/docs/api-routes/introduction -import * as Sentry from '@sentry/nextjs'; +import { withSentry } from '@sentry/nextjs'; const handler = async (req, res) => { // throw new Error('API Test 4') res.status(200).json({ name: 'John Doe' }) } -export default Sentry.withSentry(handler); -``` \ No newline at end of file +export default withSentry(handler); +``` diff --git a/src/includes/getting-started-verify/javascript.nextjs.mdx b/src/includes/getting-started-verify/javascript.nextjs.mdx index 2fd62ad614124..6bf6a93130c6f 100644 --- a/src/includes/getting-started-verify/javascript.nextjs.mdx +++ b/src/includes/getting-started-verify/javascript.nextjs.mdx @@ -12,14 +12,14 @@ And throw an error in an API route: ```javascript {filename:pages/api/hello.js} // Next.js API route support: https://nextjs.org/docs/api-routes/introduction -import * as Sentry from '@sentry/nextjs'; +import { withSentry } from '@sentry/nextjs'; const handler = async (req, res) => { throw new Error('API throw error test') res.status(200).json({ name: 'John Doe' }) } -export default Sentry.withSentry(handler); +export default withSentry(handler); ``` From 7a11d7662cf658da0d6dfe1fcf91fab1c1a5cbf7 Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Tue, 27 Apr 2021 11:31:59 +0200 Subject: [PATCH 4/6] ref: Remove comment --- src/includes/getting-started-config/javascript.nextjs.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/includes/getting-started-config/javascript.nextjs.mdx b/src/includes/getting-started-config/javascript.nextjs.mdx index 9ce8b91bfa21f..7193f5b282d8f 100644 --- a/src/includes/getting-started-config/javascript.nextjs.mdx +++ b/src/includes/getting-started-config/javascript.nextjs.mdx @@ -23,7 +23,6 @@ To capture server / API route errors you need to wrap your handlers with a Sentr import { withSentry } from '@sentry/nextjs'; const handler = async (req, res) => { - // throw new Error('API Test 4') res.status(200).json({ name: 'John Doe' }) } From 82324697a8a77604053567bd4ec67b1ea943a548 Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Tue, 27 Apr 2021 14:34:27 +0200 Subject: [PATCH 5/6] Update src/includes/getting-started-verify/javascript.nextjs.mdx Co-authored-by: iker barriocanal <32816711+iker-barriocanal@users.noreply.github.com> --- src/includes/getting-started-verify/javascript.nextjs.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/includes/getting-started-verify/javascript.nextjs.mdx b/src/includes/getting-started-verify/javascript.nextjs.mdx index 6bf6a93130c6f..29a745cd070d2 100644 --- a/src/includes/getting-started-verify/javascript.nextjs.mdx +++ b/src/includes/getting-started-verify/javascript.nextjs.mdx @@ -1,6 +1,6 @@ Add a button to a frontend component that throws an error: -```javascript {filename:index.js} +```javascript {filename:pages/index.js}