Skip to content

Commit d1b11e8

Browse files
inventarSarahchargome
authored andcommitted
move content about error capturing to "Capturing Errors and Events" from "Manual Setup" (Next.js) (#12786)
* move capture error content * adapt formatting * formatting fix Co-authored-by: Charly Gomez <[email protected]> --------- Co-authored-by: Charly Gomez <[email protected]>
1 parent 83cb6ce commit d1b11e8

File tree

2 files changed

+49
-47
lines changed

2 files changed

+49
-47
lines changed

docs/platforms/javascript/guides/nextjs/manual-setup.mdx

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -239,53 +239,6 @@ export default function GlobalError({ error }) {
239239
}
240240
```
241241

242-
Note that if you create [Next.js error.js files](https://nextjs.org/docs/app/building-your-application/routing/error-handling), these files will take precedence over the `global-error.js` file.
243-
This means, that if you want to report errors that are caught by `error.js` files, you need to manually capture them:
244-
245-
```tsx {filename:error.tsx}
246-
"use client";
247-
248-
import { useEffect } from "react";
249-
import * as Sentry from "@sentry/nextjs";
250-
251-
export default function ErrorPage({
252-
error,
253-
}: {
254-
error: Error & { digest?: string };
255-
}) {
256-
useEffect(() => {
257-
// Log the error to Sentry
258-
Sentry.captureException(error);
259-
}, [error]);
260-
261-
return (
262-
<div>
263-
<h2>Something went wrong!</h2>
264-
</div>
265-
);
266-
}
267-
```
268-
269-
```jsx {filename:error.jsx}
270-
"use client";
271-
272-
import { useEffect } from "react";
273-
import * as Sentry from "@sentry/nextjs";
274-
275-
export default function ErrorPage({ error }) {
276-
useEffect(() => {
277-
// Log the error to Sentry
278-
Sentry.captureException(error);
279-
}, [error]);
280-
281-
return (
282-
<div>
283-
<h2>Something went wrong!</h2>
284-
</div>
285-
);
286-
}
287-
```
288-
289242
#### Errors from Nested React Server Components
290243

291244
_Requires `@sentry/nextjs` version `8.28.0` or higher and Next.js 15._

platform-includes/capture-error/javascript.nextjs.mdx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,52 @@ try {
99
Sentry.captureException(err);
1010
}
1111
```
12+
13+
### Capturing Errors in `error.js` Files
14+
15+
Note that if you create [Next.js error.js files](https://nextjs.org/docs/app/building-your-application/routing/error-handling), these files will take precedence over any global error handling.
16+
This means, that if you want to report errors that are caught by `error.js` files, you need to manually capture them:
17+
18+
```tsx {filename:error.tsx}
19+
"use client";
20+
21+
import { useEffect } from "react";
22+
import * as Sentry from "@sentry/nextjs";
23+
24+
export default function ErrorPage({
25+
error,
26+
}: {
27+
error: Error & { digest?: string };
28+
}) {
29+
useEffect(() => {
30+
// Log the error to Sentry
31+
Sentry.captureException(error);
32+
}, [error]);
33+
34+
return (
35+
<div>
36+
<h2>Something went wrong!</h2>
37+
</div>
38+
);
39+
}
40+
```
41+
42+
```jsx {filename:error.jsx}
43+
"use client";
44+
45+
import { useEffect } from "react";
46+
import * as Sentry from "@sentry/nextjs";
47+
48+
export default function ErrorPage({ error }) {
49+
useEffect(() => {
50+
// Log the error to Sentry
51+
Sentry.captureException(error);
52+
}, [error]);
53+
54+
return (
55+
<div>
56+
<h2>Something went wrong!</h2>
57+
</div>
58+
);
59+
}
60+
```

0 commit comments

Comments
 (0)