have better transaction errors
This commit is contained in:
parent
184480ad36
commit
bcfc4d1fd7
1 changed files with 17 additions and 2 deletions
|
@ -90,13 +90,28 @@ export function reqAsPromise(req) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function txnAsPromise(txn) {
|
export function txnAsPromise(txn) {
|
||||||
|
let error;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
txn.addEventListener("complete", () => {
|
txn.addEventListener("complete", () => {
|
||||||
resolve();
|
resolve();
|
||||||
needsSyncPromise && Promise._flush && Promise._flush();
|
needsSyncPromise && Promise._flush && Promise._flush();
|
||||||
});
|
});
|
||||||
txn.addEventListener("abort", () => {
|
txn.addEventListener("error", event => {
|
||||||
reject(new IDBRequestError(txn));
|
const request = event.target;
|
||||||
|
// catch first error here, but don't reject yet,
|
||||||
|
// as we don't have access to the failed request in the abort event handler
|
||||||
|
if (!error && request) {
|
||||||
|
error = new IDBRequestError(request);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
txn.addEventListener("abort", event => {
|
||||||
|
if (!error) {
|
||||||
|
const txn = event.target;
|
||||||
|
const dbName = txn.db.name;
|
||||||
|
const storeNames = Array.from(txn.objectStoreNames).join(", ")
|
||||||
|
error = new StorageError(`Transaction on ${dbName} with stores ${storeNames} was aborted.`);
|
||||||
|
}
|
||||||
|
reject(error);
|
||||||
needsSyncPromise && Promise._flush && Promise._flush();
|
needsSyncPromise && Promise._flush && Promise._flush();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue