Skip to content

Commit c0a06cc

Browse files
Handle the server down scenario
1 parent 72b0886 commit c0a06cc

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

client/src/components/app.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, {useState} from "react";
22
import history from "../history";
33
import {Router, Route, Switch} from 'react-router-dom';
44
import log from "loglevel"
@@ -17,12 +17,17 @@ import {BadRequest} from "./ui/error/badRequest";
1717

1818
const App = () => {
1919
log.info(`[App]: Rendering App Component`)
20+
const [serverError, setServerError] = useState(false);
21+
22+
const setServerErrorHandler = () => {
23+
setServerError(true)
24+
}
2025

2126
return (
2227
<Router history={history}>
23-
<NavBar/>
28+
<NavBar errorHandler={setServerErrorHandler}/>
2429
<TabPanelList/>
25-
<Switch>
30+
{serverError ? null: <Switch>
2631
<Route path="/" exact component={Home}/>
2732
<Route path="/login" exact component={Login}/>
2833
<Route path="/signup" exact component={SignUp}/>
@@ -34,7 +39,7 @@ const App = () => {
3439
<Route path="/checkout/success-payment/:id" exact component={SuccessPayment}/>
3540
<Route path="/checkout/cancel-payment/:id" exact component={CancelPayment}/>
3641
<Route path="*" exact component={BadRequest}/>
37-
</Switch>
42+
</Switch>}
3843
</Router>
3944
)
4045
}

client/src/components/routes/navbar/navBar.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ const NavBar = props => {
114114
} else {
115115
if (tabsAPIData.hasOwnProperty("statusCode")) {
116116
log.info(`[NavBar]: tabsAPIData.statusCode = ${tabsAPIData.statusCode}`)
117+
props.errorHandler()
117118
return <HTTPError statusCode={tabsAPIData.statusCode}/>
118119
}
119120
}

0 commit comments

Comments
 (0)