Skip to content

Commit c7a17d2

Browse files
HazATkamilogorekiker-barriocanalPeloWriter
authored
feat: Ref update next.js config (#3472)
Co-authored-by: Kamil Ogórek <[email protected]> Co-authored-by: iker barriocanal <[email protected]> Co-authored-by: Fiona <[email protected]>
1 parent 1e99cc6 commit c7a17d2

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/includes/getting-started-config/javascript.nextjs.mdx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,17 @@ See [manual configuration](/platforms/javascript/guides/nextjs/manual-setup/) fo
1414

1515
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.
1616

17-
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).
17+
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).
18+
19+
To capture server/API route errors, you need to wrap your handlers with a Sentry function:
20+
21+
```javascript
22+
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
23+
import { withSentry } from '@sentry/nextjs';
24+
25+
const handler = async (req, res) => {
26+
res.status(200).json({ name: 'John Doe' })
27+
}
28+
29+
export default withSentry(handler);
30+
```
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Add a button to a frontend component that throws an error:
2+
3+
```javascript {filename:pages/index.js}
4+
<button type="button" onClick={() => {
5+
throw new Error("Sentry Frontend Error");
6+
}}>
7+
Throw error
8+
</button>
9+
```
10+
11+
And throw an error in an API route:
12+
13+
```javascript {filename:pages/api/hello.js}
14+
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
15+
import { withSentry } from '@sentry/nextjs';
16+
17+
const handler = async (req, res) => {
18+
throw new Error('API throw error test')
19+
res.status(200).json({ name: 'John Doe' })
20+
}
21+
22+
export default withSentry(handler);
23+
```
24+
<Note>
25+
26+
Errors triggered from within Browser DevTools are sandboxed, so will not trigger an error handler. Place the snippet directly in your code instead.
27+
28+
</Note>

0 commit comments

Comments
 (0)