-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy path_error.jsx
37 lines (33 loc) · 1.05 KB
/
_error.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// This customization of Next.js's default error page allows us to send
// unexpected errors to New Relic so that they can be viewed in the dashboard.
//
// See https://nextjs.org/docs/pages/building-your-application/routing/custom-error#more-advanced-error-page-customizing
function Error({ statusCode }) {
return (
<p>
{statusCode
? `An error ${statusCode} occurred on server`
: 'An error occurred on client'}
</p>
)
}
Error.getInitialProps = async function ({ res, err }) {
if (typeof window === 'undefined') {
// The error has occurred on the server-side. So we utilize the standard
// Node.js module for reporting the error.
const newrelic = await import('newrelic')
newrelic.noticeError(err)
} else {
// The error has occurred on the client-size. So we utilize the browser
// agent to report the error.
window.newrelic.noticeError(err)
}
let statusCode
if (res) {
statusCode = res.statusCode
} else {
statusCode = err?.statusCode || 404
}
return { statusCode }
}
export default Error