From d2ea5efa43efcb9fa717613eaa3901816cef0aa0 Mon Sep 17 00:00:00 2001 From: nthouliss Date: Thu, 31 Mar 2022 19:21:07 +1100 Subject: [PATCH] Add guard clause for errors on ImportExportModal --- src/modals/ImportExportModal.tsx | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/modals/ImportExportModal.tsx b/src/modals/ImportExportModal.tsx index da64d47..9a8d866 100644 --- a/src/modals/ImportExportModal.tsx +++ b/src/modals/ImportExportModal.tsx @@ -103,15 +103,17 @@ function ImportExportModal({ } catch (e) { setIsLoading(false); backgroundTaskRunningRef.current = false; - if (e.message.startsWith("Max buffer length exceeded")) { - setError( - new Error( - "Max image size exceeded ensure your database doesn't have an image over 100MB" - ) - ); - } else { - console.error(e); - setError(e); + if (e instanceof(Error)) { + if (e.message.startsWith("Max buffer length exceeded")) { + setError( + new Error( + "Max image size exceeded ensure your database doesn't have an image over 100MB" + ) + ); + } else { + console.error(e); + setError(e); + } } } // Set file input to null to allow adding the same data 2 times in a row @@ -393,9 +395,11 @@ function ImportExportModal({ const blob = new Blob([buffer]); saveAs(blob, `${shortid.generate()}.owlbear`); addSuccessToast("Exported", checkedMaps, checkedTokens); - } catch (e) { - console.error(e); - setError(e); + } catch (e: unknown) { + if (e instanceof(Error)) { + console.error(e); + setError(e); + } } setIsLoading(false); backgroundTaskRunningRef.current = false;