Closed tanyaMel closed 2 years ago
I found how to catch "AbortError": instead of
await storage.add(obj)
await transaction.done
I wrote
await Promise.all([storage.add(obj), transaction.done])
.
But I don't understand why it's work.
In the first way code is waiting resolve/reject promises storage.add
and transaction.done
operations. And in the second way Promise.all waits the same.
Tell me please what did I miss?
UPD: I read about "Fail Fast". But... why I can't catch "AbortError" in the try/catch by this (it's still uncauth error):
...
try {
const storageName = "rates"
const obj = { position: "position", rate: "1600.58" }
const transaction = db.transaction(storageName, "readwrite")
const storage = transaction.objectStore(storageName)
await storage.add(obj)
await transaction.done
} catch (e) {
console.error(e)
}
...
I'm sorry. I found answer in #256
Thank you so much for this package!
Hello! :)
I'm using this amasing package and writting unit tests to get sure that everything works fine. And I was surprised by an unexpected "AbortError". It occurs when adding an obj with key that already exists while should be just error "Key already exists in the object store".
Steps to reproduce: 1) set "keyPath" in store; 2) add first value with unique "keyPath" (there's no errors in console); 3) try to add another one with "keyPath" value from step 2; 4) check errors in console.
For example, I set action to always add object "{ position: "position", rate: "1600.58" }" on page button. In the store "keyPath" is "position". When I click first time everything is OK. But when I click second time and others - there's not only "Key already exists in the object store" that I expect but "AbortError". This error brokes my unit tests because I can't catch and handle it.
Here's console messages: And the source:
I create class to not use indexeddb directly. There's method
add
in this class. Here's code:If I use just
store.add
not in class, like this:It's still occurs "AbotError".
What I'm doing wrong?
General technologies: