Skip to content

Commit

Permalink
Fix infinite request loop if metadata request fails (#3948)
Browse files Browse the repository at this point in the history
Fixes #3812. Previously, the UI would retry the metadata request indefinitely and without a delay. Now, if the metadata request fails, an error message and a button to reload the page are displayed.

I haven’t implemented automatic retries with back-offs for now, as this adds complexity and I’m not sure it’s necessary.
  • Loading branch information
tillprochaska authored Oct 22, 2024
1 parent fd7935b commit 19adc88
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
39 changes: 31 additions & 8 deletions ui/src/app/Router.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { Component, Suspense } from 'react';
import { Route, Routes } from 'react-router-dom';
import { connect } from 'react-redux';
import { Spinner, Classes } from '@blueprintjs/core';
import { Button, Spinner, Classes } from '@blueprintjs/core';
import { FormattedMessage, injectIntl } from 'react-intl';

import { fetchMetadata, fetchMessages, dismissMessage } from 'actions';
import {
Expand Down Expand Up @@ -60,11 +61,11 @@ class Router extends Component {
fetchIfNeeded() {
const { metadata, messages } = this.props;

if (metadata.shouldLoad) {
if (metadata.shouldLoad && !metadata.isError) {
this.props.fetchMetadata();
}

if (messages.shouldLoad) {
if (messages.shouldLoad && !messages.isError) {
this.fetchMessages();
}
}
Expand Down Expand Up @@ -92,23 +93,44 @@ class Router extends Component {
const { metadata, session, pinnedMessage, dismissMessage } = this.props;
const isLoaded = metadata && metadata.app && session;

const Loading = (
<div className="RouterLoading">
<div className="spinner">
if (metadata.isError) {
return (
<div className="Router">
<div className="Router__error">
<p className={Classes.TEXT_LARGE}>
<FormattedMessage
id="router.error.message"
defaultMessage="Sorry, something went wrong and Aleph couldn’t load. Please try again in a few minutes or contact an administrator if the error persists."
/>
</p>
<Button large icon="reset" onClick={() => window.location.reload()}>
<FormattedMessage
id="router.error.retry"
defaultMessage="Retry"
/>
</Button>
</div>
</div>
);
}

const loading = (
<div className="Router">
<div className="Router__spinner">
<Spinner className={Classes.LARGE} />
</div>
</div>
);

if (!isLoaded) {
return Loading;
return loading;
}

return (
<>
<Navbar />
<MessageBanner message={pinnedMessage} onDismiss={dismissMessage} />
<Suspense fallback={Loading}>
<Suspense fallback={loading}>
<Routes>
<Route path="oauth" element={<OAuthScreen />} />
<Route path="logout" element={<LogoutScreen />} />
Expand Down Expand Up @@ -164,4 +186,5 @@ export default connect(mapStateToProps, {
fetchMetadata,
fetchMessages,
dismissMessage,
injectIntl,
})(Router);
17 changes: 12 additions & 5 deletions ui/src/app/Router.scss
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
@import 'app/variables.scss';

.RouterLoading {
.Router {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}

.Router__error,
.Router__spinner {
align-self: center;
margin: auto;
}

.spinner {
align-self: center;
margin: auto;
}
.Router__error {
max-width: $aleph-screen-sm-max-width;
padding: $aleph-content-padding;
text-align: center;
}

0 comments on commit 19adc88

Please sign in to comment.