Skip to content

Commit

Permalink
show error gui when initial json loading fails
Browse files Browse the repository at this point in the history
  • Loading branch information
xinaesthete committed Feb 19, 2025
1 parent ee1c0f2 commit 44e9ee8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/dataloaders/DataLoaderUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,30 @@ import {
getLocalCompressedBinaryDataLoader,
} from "./DataLoaders";
import type { DataColumn, DataType, LoadedDataColumn } from "@/charts/charts";
import { createMdvPortal } from "@/react/react_utils";
import ErrorComponentReactWrapper from "@/react/components/ErrorComponentReactWrapper";

let projectRoot = "";
export async function fetchJsonConfig(url: string, root: string) {
/**
* This could potentially also have some more awareness of what type of json it is fetching, and e.g. do some zod validation
*/
export async function fetchJsonConfig(url: string, root: string) {
try {
const resp = await fetch(url);
const config = await resp.json();
if (!resp.ok) {
throw new Error(JSON.stringify(config, null, 2));
}
//rewriteBaseUrlRecursive(config, root); //removed.
return config;
} catch (e) {
console.error(`Error fetching ${url}: ${e}`);
return { error: e };
} catch (error: any) {
//todo less hacky CSS - also consider making the dialog open by default
document.body.style.display = "flex";
document.body.style.justifyContent = "center";
document.body.style.alignItems = "center";
createMdvPortal(ErrorComponentReactWrapper({ error: {message: `Error fetching JSON '${url}'`}, extraMetaData: {message: `${error}`} }), document.body);
console.error(`Error fetching ${url}: ${error}`);
return { error };
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/react/components/ErrorComponentReactWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const ErrorComponent = ({error, extraMetaData}: ErrorComponentType) => {
},
}}
>
ERROR: Click to view details
{error.message} (click to view details or submit a bug report)
</Button>
</Alert>
<ReusableDialog
Expand Down

0 comments on commit 44e9ee8

Please sign in to comment.