Skip to content

Commit 7cf5750

Browse files
show error message when app is down
1 parent a05e43e commit 7cf5750

File tree

4 files changed

+62
-16
lines changed

4 files changed

+62
-16
lines changed

client/packages/lowcoder/src/app.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import GlobalInstances from 'components/GlobalInstances';
5858
import { fetchHomeData } from "./redux/reduxActions/applicationActions";
5959
import { getNpmPackageMeta } from "./comps/utils/remote";
6060
import { packageMetaReadyAction, setLowcoderCompsLoading } from "./redux/reduxActions/npmPluginActions";
61+
import ErrorFallback from "./components/ErrorFallback";
6162

6263
const LazyUserAuthComp = React.lazy(() => import("pages/userAuth"));
6364
const LazyInviteLanding = React.lazy(() => import("pages/common/inviteLanding"));
@@ -89,7 +90,9 @@ type AppIndexProps = {
8990
currentUserAnonymous: boolean;
9091
orgDev: boolean;
9192
defaultHomePage: string | null | undefined;
93+
fetchHomeOrgFinished: boolean;
9294
fetchHomeDataFinished: boolean;
95+
fetchHomeDataError: boolean;
9396
fetchConfig: (orgId?: string) => void;
9497
fetchHomeData: (currentUserAnonymous?: boolean | undefined) => void;
9598
fetchLowcoderCompVersions: () => void;
@@ -130,9 +133,14 @@ class AppIndex extends React.Component<AppIndexProps, any> {
130133
/* if (isLocalhost || isLowCoderDomain) {
131134
posthog.init('phc_lD36OXeppUehLgI33YFhioTpXqThZ5QqR8IWeKvXP7f', { api_host: 'https://eu.i.posthog.com', person_profiles: 'always' });
132135
} */
133-
136+
137+
// show error message when /home endpoint fails
138+
if (this.props.fetchHomeDataFinished && this.props.fetchHomeDataError) {
139+
return <ErrorFallback />
140+
}
141+
134142
// make sure all users in this app have checked login info
135-
if (!this.props.isFetchUserFinished || (this.props.currentUserId && !this.props.fetchHomeDataFinished)) {
143+
if (!this.props.isFetchUserFinished || (this.props.currentUserId && !this.props.fetchHomeOrgFinished)) {
136144
const hideLoadingHeader = isTemplate || isAuthUnRequired(pathname);
137145
return <ProductLoading hideHeader={hideLoadingHeader} />;
138146
}
@@ -409,7 +417,9 @@ const mapStateToProps = (state: AppState) => ({
409417
currentUserAnonymous: state.ui.users.user.isAnonymous,
410418
currentOrgId: state.ui.users.user.currentOrgId,
411419
defaultHomePage: state.ui.application.homeOrg?.commonSettings.defaultHomePage,
412-
fetchHomeDataFinished: Boolean(state.ui.application.homeOrg?.commonSettings),
420+
fetchHomeOrgFinished: Boolean(state.ui.application.homeOrg?.commonSettings),
421+
fetchHomeDataFinished: state.ui.application.loadingStatus.fetchHomeDataFinished,
422+
fetchHomeDataError: state.ui.application.fetchHomeDataError,
413423
favicon: getBrandingConfig(state)?.favicon
414424
? buildMaterialPreviewURL(getBrandingConfig(state)?.favicon!)
415425
: favicon,
@@ -449,7 +459,7 @@ export function bootstrap() {
449459
const root = createRoot(container!);
450460
root.render(
451461
<Provider store={reduxStore}>
452-
<AppIndexWithProps />
462+
<AppIndexWithProps />
453463
</Provider>
454464
);
455465
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import Flex from "antd/es/flex";
2+
import { WarningIcon } from "lowcoder-design";
3+
4+
const ErrorFallback = (props: {
5+
heading?: string,
6+
buttonText?: string,
7+
onButtonClick?: () => void,
8+
}) => (
9+
<Flex align="center" justify="center" vertical style={{
10+
height: '90vh',
11+
width: '400px',
12+
margin: '0 auto',
13+
}}>
14+
<WarningIcon width={'100px'} height={'100px'} />
15+
<h1 style={{marginTop: '20px', marginBottom: '20px' }}>
16+
{Boolean(props.heading) ? props.heading : 'Oops, Something went wrong!'}
17+
</h1>
18+
<button
19+
onClick={() => {
20+
if(props.onButtonClick) {
21+
return props?.onButtonClick();
22+
}
23+
window.location.reload();
24+
}}
25+
style={{
26+
background: '#4965f2',
27+
border: '1px solid #4965f2',
28+
color: '#ffffff',
29+
borderRadius:'6px',
30+
fontSize: '16px',
31+
padding: '10px 28px',
32+
}}>
33+
{Boolean(props.buttonText) ? props.buttonText : 'Reload'}
34+
</button>
35+
</Flex>
36+
);
37+
38+
export default ErrorFallback;

client/packages/lowcoder/src/pages/editor/AppEditor.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import dayjs from "dayjs";
3636
import { currentApplication } from "@lowcoder-ee/redux/selectors/applicationSelector";
3737
import { notificationInstance } from "components/GlobalInstances";
3838
import { AppState } from "@lowcoder-ee/redux/reducers";
39+
import ErrorFallback from "@lowcoder-ee/components/ErrorFallback";
3940

4041
const AppSnapshot = lazy(() => {
4142
return import("pages/editor/appSnapshot")
@@ -191,17 +192,6 @@ const AppEditor = React.memo(() => {
191192
}
192193
}, [isLowcoderCompLoading, fetchApplication]);
193194

194-
const fallbackUI = useMemo(() => (
195-
<Flex align="center" justify="center" vertical style={{
196-
height: '300px',
197-
width: '400px',
198-
margin: '0 auto',
199-
}}>
200-
<h4 style={{margin: 0}}>Something went wrong while displaying this webpage</h4>
201-
<button onClick={() => history.push(ALL_APPLICATIONS_URL)} style={{background: '#4965f2',border: '1px solid #4965f2', color: '#ffffff',borderRadius:'6px'}}>Go to Apps</button>
202-
</Flex>
203-
), []);
204-
205195
if (Boolean(appError)) {
206196
return (
207197
<Flex align="center" justify="center" vertical style={{
@@ -216,7 +206,12 @@ const AppEditor = React.memo(() => {
216206
}
217207

218208
return (
219-
<ErrorBoundary fallback={fallbackUI}>
209+
<ErrorBoundary fallback={
210+
<ErrorFallback
211+
buttonText="Go to Apps"
212+
onButtonClick={() => history.push(ALL_APPLICATIONS_URL)}
213+
/>
214+
}>
220215
{showAppSnapshot ? (
221216
<Suspense fallback={<EditorSkeletonView />}>
222217
<AppSnapshot

client/packages/lowcoder/src/redux/reducers/uiReducers/applicationReducer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const initialState: ApplicationReduxState = {
3333
fetchingAppDetail: false,
3434
applicationPublishing: false,
3535
},
36+
fetchHomeDataError: false,
3637
};
3738

3839
const usersReducer = createReducer(initialState, {
@@ -91,6 +92,7 @@ const usersReducer = createReducer(initialState, {
9192
isFetchingHomeData: false,
9293
fetchHomeDataFinished: true,
9394
},
95+
fetchHomeDataError: true,
9496
}),
9597
[ReduxActionTypes.FETCH_APPLICATION_RECYCLE_LIST_SUCCESS]: (
9698
state: ApplicationReduxState,
@@ -356,6 +358,7 @@ export interface ApplicationReduxState {
356358
fetchingAppDetail: boolean; // dsl in detail
357359
applicationPublishing: boolean;
358360
};
361+
fetchHomeDataError: boolean;
359362
}
360363

361364
export default usersReducer;

0 commit comments

Comments
 (0)