Skip to content

Commit 200aa20

Browse files
committed
Updated next.js error handler to use error reporting api.
1 parent 175e50e commit 200aa20

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/app/error.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
// app/error.tsx
2+
13
'use client' // Error boundaries must be Client Components
24

35
import { useEffect } from 'react'
6+
import { reportError } from '@/lib/errorReportingService' // 1. Import the service
47

58
export default function Error({
69
error,
@@ -10,18 +13,24 @@ export default function Error({
1013
reset: () => void
1114
}) {
1215
useEffect(() => {
13-
// Log the error to an error reporting service
14-
console.error(error)
16+
// 2. Log the error to your reporting service instead of just the console
17+
reportError(error)
1518
}, [error])
1619

1720
return (
18-
<div>
21+
<div style={{ padding: '2rem', textAlign: 'center' }}>
1922
<h2>Something went wrong!</h2>
23+
<p>An error occurred while loading this page.</p>
2024
<button
2125
onClick={
2226
// Attempt to recover by trying to re-render the segment
2327
() => reset()
2428
}
29+
style={{
30+
marginTop: '1rem',
31+
padding: '0.5rem 1rem',
32+
cursor: 'pointer',
33+
}}
2534
>
2635
Try again
2736
</button>

0 commit comments

Comments
 (0)