fix: handle error when definition load fails (#1979)

This commit is contained in:
AlexVarchuk 2022-05-05 15:49:08 +03:00 committed by GitHub
parent 186f5a98bd
commit 508ebd58a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,6 +33,10 @@ export function StoreBuilder(props: StoreBuilderProps) {
const { spec, specUrl, options, onLoaded, children } = props; const { spec, specUrl, options, onLoaded, children } = props;
const [resolvedSpec, setResolvedSpec] = React.useState<any>(null); const [resolvedSpec, setResolvedSpec] = React.useState<any>(null);
const [error, setError] = React.useState<Error | null>(null);
if (error) {
throw error;
}
React.useEffect(() => { React.useEffect(() => {
async function load() { async function load() {
@ -40,8 +44,13 @@ export function StoreBuilder(props: StoreBuilderProps) {
return undefined; return undefined;
} }
setResolvedSpec(null); setResolvedSpec(null);
try {
const resolved = await loadAndBundleSpec(spec || specUrl!); const resolved = await loadAndBundleSpec(spec || specUrl!);
setResolvedSpec(resolved); setResolvedSpec(resolved);
} catch (e) {
setError(e);
throw e;
}
} }
load(); load();
}, [spec, specUrl]); }, [spec, specUrl]);