mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
abort upgrade txn on error
This commit is contained in:
parent
a61f052fe8
commit
0c05e97465
@ -66,11 +66,18 @@ export function decodeUint32(str) {
|
|||||||
|
|
||||||
export function openDatabase(name, createObjectStore, version, idbFactory = window.indexedDB) {
|
export function openDatabase(name, createObjectStore, version, idbFactory = window.indexedDB) {
|
||||||
const req = idbFactory.open(name, version);
|
const req = idbFactory.open(name, version);
|
||||||
req.onupgradeneeded = (ev) => {
|
req.onupgradeneeded = async (ev) => {
|
||||||
const db = ev.target.result;
|
const db = ev.target.result;
|
||||||
const txn = ev.target.transaction;
|
const txn = ev.target.transaction;
|
||||||
const oldVersion = ev.oldVersion;
|
const oldVersion = ev.oldVersion;
|
||||||
createObjectStore(db, txn, oldVersion, version);
|
try {
|
||||||
|
await createObjectStore(db, txn, oldVersion, version);
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Aborting upgrade transaction because migration threw error");
|
||||||
|
console.log(err.message);
|
||||||
|
console.log(err.stack);
|
||||||
|
txn.abort();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
return reqAsPromise(req);
|
return reqAsPromise(req);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user