generated from idea2app/Next-Bootstrap-ts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
_error.tsx
33 lines (25 loc) · 1.03 KB
/
_error.tsx
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
import * as Sentry from '@sentry/nextjs';
import { parseCookie, parseLanguageHeader } from 'mobx-i18n';
import type { NextPage } from 'next';
import type { ErrorProps } from 'next/error';
import Error from 'next/error';
import { NotFoundCard } from '../components/NotFoundCard';
import { i18n } from '../models/Translation';
const CustomErrorComponent: NextPage<ErrorProps> = props => (
<>
<Error {...props} />
<NotFoundCard {...props} />
</>
);
const enableSentry =
process.env.NODE_ENV === 'development' || !process.env.SENTRY_AUTH_TOKEN;
CustomErrorComponent.getInitialProps = async contextData => {
const { 'accept-language': acceptLanguage, cookie = '' } =
contextData.req!.headers;
const { language } = parseCookie(cookie),
languages = parseLanguageHeader(acceptLanguage || '');
await i18n.loadLanguages([language, ...languages].filter(Boolean));
if (enableSentry) await Sentry.captureUnderscoreErrorException(contextData);
return Error.getInitialProps(contextData);
};
export default CustomErrorComponent;