From 4e7ed1d625e9705cfd6833e68ba7955064304a0a Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Sun, 6 Jun 2021 19:27:23 +1000 Subject: [PATCH] Add better optional handling to db error handler --- src/contexts/DatabaseContext.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/contexts/DatabaseContext.js b/src/contexts/DatabaseContext.js index 40c5198..0ae94b1 100644 --- a/src/contexts/DatabaseContext.js +++ b/src/contexts/DatabaseContext.js @@ -58,18 +58,18 @@ export function DatabaseProvider({ children }) { function handleDatabaseError(event) { event.preventDefault(); - if (event.reason?.message.startsWith("QuotaExceededError")) { + if (event?.reason?.message?.startsWith("QuotaExceededError")) { setDatabaseError({ - name: event.reason.name, + name: event?.reason?.name, message: "Storage Quota Exceeded Please Clear Space and Try Again.", }); } else { setDatabaseError({ - name: event.reason.name, + name: event?.reason?.name, message: "Something went wrong, please refresh your browser.", }); } - console.error(event.reason); + console.error(event?.reason); } window.addEventListener("unhandledrejection", handleDatabaseError);