From b7793626cfb46e4a3eb1583803f96e2fee6cdbff Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Mon, 28 Jun 2021 08:24:48 +1000 Subject: [PATCH] Fix database error not showing the right message --- src/contexts/DatabaseContext.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/contexts/DatabaseContext.js b/src/contexts/DatabaseContext.js index 477fe4e..b797dbf 100644 --- a/src/contexts/DatabaseContext.js +++ b/src/contexts/DatabaseContext.js @@ -72,16 +72,24 @@ export function DatabaseProvider({ children }) { function handleDatabaseError(event) { if (event) { event.preventDefault(); - if (event.reason instanceof Dexie.QuotaExceededError) { - setDatabaseError({ - name: event.reason?.name, - message: "Storage Quota Exceeded Please Clear Space and Try Again.", - }); - } else if (event.reason instanceof Dexie.DatabaseClosedError) { - setDatabaseError({ - name: event.reason?.name, - message: "Database closed, please refresh your browser.", - }); + if (event.reason instanceof Dexie.DexieError) { + if (event.reason?.inner?.name === "QuotaExceededError") { + setDatabaseError({ + name: event.reason?.name, + message: + "Storage Quota Exceeded Please Clear Space and Try Again.", + }); + } else if (event.reason?.inner?.name === "DatabaseClosedError") { + setDatabaseError({ + name: event.reason?.name, + message: "Database closed, please refresh your browser.", + }); + } else { + setDatabaseError({ + name: event.reason?.name, + message: "Something went wrong, please refresh your browser.", + }); + } } else { setDatabaseError({ name: event.reason?.name,