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);
const resolved = await loadAndBundleSpec(spec || specUrl!); try {
setResolvedSpec(resolved); const resolved = await loadAndBundleSpec(spec || specUrl!);
setResolvedSpec(resolved);
} catch (e) {
setError(e);
throw e;
}
} }
load(); load();
}, [spec, specUrl]); }, [spec, specUrl]);