jakearchibald / idb

IndexedDB, but with promises
https://www.npmjs.com/package/idb
ISC License
6.39k stars 361 forks source link

An aborted transaction should not throw null #144

Closed birtles closed 4 years ago

birtles commented 4 years ago

Currently for both error and abort events, transactions run the same event handler (see this code):

const error = () => {
  reject(tx.error);
  unlisten();
};
// ...
tx.addEventListener('error', error);
tx.addEventListener('abort', error);

However, when a transaction is aborted, tx.error may be null as per the spec.

Having await tx.done throw null is a bit confusing. Perhaps we should have a separate event handler for abort that rejects with an AbortError if tx.error === null?

jakearchibald commented 4 years ago

Agreed. AbortError is the right thing here.