Handle errors when attempting to clear IndexedDB store

This commit is contained in:
JC Brand 2020-01-06 10:37:09 +01:00
parent 1653c1ae92
commit 30bd4d34c9

View File

@ -223,14 +223,19 @@
function clearIndexedDB () { function clearIndexedDB () {
const promise = u.getResolveablePromise(); const promise = u.getResolveablePromise();
const DBOpenRequest = window.indexedDB.open("converse-test-persistent"); const db_request = window.indexedDB.open("converse-test-persistent");
DBOpenRequest.onsuccess = function () { db_request.onsuccess = function () {
const db = DBOpenRequest.result; const db = db_request.result;
const bare_jid = "romeo@montague.lit"; const bare_jid = "romeo@montague.lit";
const objectStore = db.transaction([bare_jid], "readwrite").objectStore(bare_jid); try {
const objectStoreRequest = objectStore.clear(); const store= db.transaction([bare_jid], "readwrite").objectStore(bare_jid);
objectStoreRequest.onsuccess = promise.resolve(); } catch (e) {
objectStoreRequest.onerror = promise.resolve(); console.error(e);
return promise.resolve();
}
const request = store.clear();
request.onsuccess = promise.resolve();
request.onerror = promise.resolve();
}; };
return promise; return promise;
} }