@@ -4,6 +4,7 @@ import { createLogger } from '@unly/utils-simple-logger';
4
4
import { ThemeProvider } from 'emotion-theming' ;
5
5
import { i18n } from 'i18next' ;
6
6
import React from 'react' ;
7
+ import ErrorPage from '../../pages/_error' ;
7
8
import customerContext from '../../stores/customerContext' ;
8
9
import i18nContext from '../../stores/i18nContext' ;
9
10
import { Theme } from '../../types/data/Theme' ;
@@ -13,6 +14,7 @@ import { SSGPageProps } from '../../types/pageProps/SSGPageProps';
13
14
import { SSRPageProps } from '../../types/pageProps/SSRPageProps' ;
14
15
import { initCustomerTheme } from '../../utils/data/theme' ;
15
16
import i18nextLocize from '../../utils/i18n/i18nextLocize' ;
17
+ import DefaultErrorLayout from '../errors/DefaultErrorLayout' ;
16
18
import BrowserPageBootstrap , { BrowserPageBootstrapProps } from './BrowserPageBootstrap' ;
17
19
import ServerPageBootstrap , { ServerPageBootstrapProps } from './ServerPageBootstrap' ;
18
20
import UniversalGlobalStyles from './UniversalGlobalStyles' ;
@@ -55,6 +57,32 @@ const MultiversalAppBootstrap: React.FunctionComponent<Props> = (props): JSX.Ele
55
57
lang,
56
58
locale,
57
59
} : MultiversalPageProps = pageProps ;
60
+
61
+ if ( ! customer || ! i18nTranslations || ! lang || ! locale ) {
62
+ // Unrecoverable error, we can't even display the layout because we don't have the minimal required information to properly do so
63
+ // This most likely means something went wrong, and we must display the error page in such case
64
+ if ( ! props . err ) {
65
+ // If the error wasn't detected by Next, then we log it to Sentry to make sure we'll be notified
66
+
67
+ Sentry . withScope ( ( scope ) : void => {
68
+ scope . setContext ( 'props' , props ) ;
69
+ Sentry . captureMessage ( `Unexpected fatal error happened, the app cannot render properly, fallback to the Error page. Check props.` , Sentry . Severity . Warning ) ;
70
+ } ) ;
71
+
72
+ } else {
73
+ // If an error was detected by Next, then it means the current state is due to a top-level that was caught before
74
+ // We don't have anything to do, as it's automatically logged into Sentry
75
+ }
76
+
77
+ return (
78
+ < ErrorPage err = { props . err } statusCode = { 500 } isReadyToRender = { true } >
79
+ < DefaultErrorLayout
80
+ error = { props . err }
81
+ />
82
+ </ ErrorPage >
83
+ ) ;
84
+ }
85
+
58
86
const i18nextInstance : i18n = i18nextLocize ( lang , i18nTranslations ) ; // Apply i18next configuration with Locize backend
59
87
const theme : Theme = initCustomerTheme ( customer ) ;
60
88
0 commit comments