-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstrumentation.ts
30 lines (30 loc) · 1012 Bytes
/
instrumentation.ts
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
export function onRequestError(
error: { digest: string } & Error,
request: {
path: string;
method: string;
headers: { [key: string]: string };
},
context: {
routerKind: 'Pages Router' | 'App Router';
routePath: string;
routeType: 'render' | 'route' | 'action' | 'middleware';
renderSource: 'react-server-components' | 'react-server-components-payload' | 'server-rendering';
revalidateReason: 'on-demand' | 'stale' | undefined;
renderType: 'dynamic' | 'dynamic-resume';
},
): void | Promise<void> {
if (process.env.NODE_ENV === 'production') {
try {
fetch(process.env.NEXT_PUBLIC_BACKEND_URL + '/error', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ message: JSON.stringify({ error: JSON.stringify(error, Object.getOwnPropertyNames(error)), request, context }) }),
});
} catch (error) {
console.error(error);
}
}
}