forked from mystiq/hydrogen-web
abort upgrade txn on error
This commit is contained in:
parent
a61f052fe8
commit
0c05e97465
1 changed files with 9 additions and 2 deletions
|
@ -66,11 +66,18 @@ export function decodeUint32(str) {
|
|||
|
||||
export function openDatabase(name, createObjectStore, version, idbFactory = window.indexedDB) {
|
||||
const req = idbFactory.open(name, version);
|
||||
req.onupgradeneeded = (ev) => {
|
||||
req.onupgradeneeded = async (ev) => {
|
||||
const db = ev.target.result;
|
||||
const txn = ev.target.transaction;
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue