Skip to content

Commit a471709

Browse files
Avoid onboarding screen if /api/organizationsIsEmpty fails (#8356)
* add error handling * remove unused imports * improve structure of try catch clause * add changelog * add margin * remove typo * move other api calls outside of try catch block * add another function call to try and catch because failure would lead to blank screen * move all methods to try catch block * improve styling
1 parent 5aacd64 commit a471709

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

CHANGELOG.unreleased.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
2121

2222
### Fixed
2323
- Fixed a bug that lead to trees being dropped when merging to trees together. [#8359](https://github.com/scalableminds/webknossos/pull/8359)
24+
- Fixed that the onboarding screen incorrectly appeared when a certain request failed. [#8356](https://github.com/scalableminds/webknossos/pull/8356)
2425
- Fixed the segment registering in coarser mags for non-mag-aligned bounding boxes. [#8364](https://github.com/scalableminds/webknossos/pull/8364)
2526

2627
### Removed

frontend/javascripts/main.tsx

+27-9
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const localStoragePersister = createSyncStoragePersister({
5353
key: "query-cache-v3",
5454
});
5555

56-
async function loadActiveUser() {
56+
async function tryToLoadActiveUser() {
5757
// Try to retrieve the currently active user if logged in
5858
try {
5959
const user = await getActiveUser({
@@ -73,12 +73,8 @@ async function loadActiveUser() {
7373

7474
async function loadHasOrganizations() {
7575
// Check whether any organizations exist
76-
try {
77-
const hasOrganizations = await checkAnyOrganizationExists();
78-
Store.dispatch(setHasOrganizationsAction(hasOrganizations));
79-
} catch (_e) {
80-
// pass
81-
}
76+
const hasOrganizations = await checkAnyOrganizationExists();
77+
Store.dispatch(setHasOrganizationsAction(hasOrganizations));
8278
}
8379

8480
async function loadOrganization() {
@@ -97,10 +93,32 @@ document.addEventListener("DOMContentLoaded", async () => {
9793
});
9894
message.config({ top: 30 });
9995
checkBrowserFeatures();
100-
await Promise.all([loadFeatureToggles(), loadActiveUser(), loadHasOrganizations()]);
101-
await Promise.all([loadOrganization()]);
10296
const containerElement = document.getElementById("main-container");
10397

98+
try {
99+
await Promise.all([
100+
loadFeatureToggles(),
101+
// This function call cannot error as it has a try-catch built-in
102+
tryToLoadActiveUser(),
103+
// *Don't* ignore errors in this request. We only want
104+
// to show an onboarding screen if the back-end replied
105+
// with hasOrganizations==true.
106+
loadHasOrganizations(),
107+
]);
108+
await loadOrganization();
109+
} catch (e) {
110+
console.error("Failed to load WEBKNOSSOS due to the following error", e);
111+
if (containerElement) {
112+
const react_root = createRoot(containerElement);
113+
react_root.render(
114+
<p style={{ margin: 20, marginTop: -20 }}>
115+
Failed to load WEBKNOSSOS. Please try again or check the console for details.
116+
</p>,
117+
);
118+
}
119+
return;
120+
}
121+
104122
if (containerElement) {
105123
const react_root = createRoot(containerElement);
106124
react_root.render(

0 commit comments

Comments
 (0)