Add error guards to catch blocks

This commit is contained in:
nthouliss 2022-04-01 14:56:55 +11:00
parent 3a0a9b231d
commit c1cde5b94f
3 changed files with 12 additions and 6 deletions

View File

@ -108,7 +108,9 @@ function DiceInteraction({
} }
}); });
} catch (error) { } catch (error) {
setError(error); if (error instanceof Error) {
setError(error);
}
} }
}, [onSceneMount]); }, [onSceneMount]);

View File

@ -562,7 +562,9 @@ export async function getGridSizeFromImage(image: HTMLImageElement) {
try { try {
prediction = await gridSizeML(image, candidates); prediction = await gridSizeML(image, candidates);
} catch (error) { } catch (error) {
logError(error); if (error instanceof Error) {
logError(error);
}
} }
if (!prediction) { if (!prediction) {

View File

@ -67,10 +67,12 @@ function useImageDrop(
} }
} }
} catch (e) { } catch (e) {
if (e.message === "Failed to fetch") { if (e instanceof Error) {
addToast("Unable to import image: failed to fetch"); if (e.message === "Failed to fetch") {
} else { addToast("Unable to import image: failed to fetch");
addToast("Unable to import image"); } else {
addToast("Unable to import image");
}
} }
} }
} }