mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-13 04:16:34 +03:00
fix: handle error when definition load fails (#1979)
This commit is contained in:
parent
186f5a98bd
commit
508ebd58a3
|
@ -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]);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user