aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-09-06 17:55:54 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-09-06 17:55:54 -0500
commitc83b9bb7444e1e6af25fe27d584db6154275396a (patch)
tree19513e231e54929aeaf901f8544726f9ac5e2fc6 /src
parent18797aa45fd45d4f3d5e70c39061324c4311983d (diff)
downloadslskd-c83b9bb7444e1e6af25fe27d584db6154275396a.tar.gz
display an error when the backend is offline
Diffstat (limited to 'src')
-rw-r--r--src/web/src/components/App.js50
1 files changed, 29 insertions, 21 deletions
diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js
index eb91e88e..d6d80492 100644
--- a/src/web/src/components/App.js
+++ b/src/web/src/components/App.js
@@ -21,6 +21,7 @@ import {
Header
} from 'semantic-ui-react';
import Rooms from './Rooms/Rooms';
+import ErrorSegment from './Shared/ErrorSegment';
const initialState = {
token: undefined,
@@ -30,7 +31,8 @@ const initialState = {
error: undefined
},
serverStateInterval: undefined,
- serverState: {}
+ serverState: {},
+ error: false,
};
class App extends Component {
@@ -39,23 +41,28 @@ class App extends Component {
componentDidMount = async () => {
const { login } = this.state;
- await this.fetchServerState();
- const securityEnabled = await session.getSecurityEnabled();
-
- if (!securityEnabled) {
- this.setToken(sessionStorage, tokenPassthroughValue)
+ try {
+ await this.fetchServerState();
+ const securityEnabled = await session.getSecurityEnabled();
+
+ if (!securityEnabled) {
+ this.setToken(sessionStorage, tokenPassthroughValue)
+ }
+
+ this.setState({
+ token: this.getToken(),
+ login: {
+ ...login,
+ initialized: true
+ },
+ serverStateInterval: window.setInterval(this.fetchServerState, 5000)
+ });
+
+ await this.checkToken();
+ } catch (err) {
+ console.error(err)
+ this.setState({ error: true })
}
-
- this.setState({
- token: this.getToken(),
- login: {
- ...login,
- initialized: true
- },
- serverStateInterval: window.setInterval(this.fetchServerState, 5000)
- });
-
- await this.checkToken();
};
componentWillUnmount = () => {
@@ -110,19 +117,20 @@ class App extends Component {
fetchServerState = async () => {
try {
this.setState({
- serverState: await server.getState()
+ serverState: await server.getState(),
+ error: false,
});
} catch (err) {
- // noop
+ this.setState({ error: true })
}
};
render = () => {
- const { token, login, serverState } = this.state;
+ const { token, login, serverState, error } = this.state;
return (
<>
- {!token ?
+ {error ? <ErrorSegment caption='slskd appears to be offline' /> : !token ?
<LoginForm
onLoginAttempt={this.login}
initialized={login.initialized}