error handling (what's the best way ?)
See original GitHub issueHi Jake.
I create my own class called utility
where I have functions. Let me clarify two functions of that class.
async writeData(storeName, val, key) {
const tx = this.db.transaction(storeName, 'readwrite');
const store = tx.objectStore(storeName);
store.put(val);
return await tx.done;
}
async readAllData(storeName) {
const tx = this.db.transaction(storeName, 'readonly');
const store = tx.objectStore(storeName);
return await store.getAll();
}
Now, I use that class in my service worker or in my app. I import this class and use these methods .
Let’s say something like this.
import IndexeddB from './utility.js'
let data = IndexedDB.readAllData('articles');
I am curious about this. If you look at the functions itself, do I have everything set up correctly? I mean I am not using onsuccess
and onerror
on the request. So return await tx.done
(is it fair to say that this will automatically throw if there’s an error and it won’t throw an error if there’s not one, to put this in a better way, where I use those functions, if I put them in try/catch
block, it’s all good and I am doing it right?
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
The Error Handling Done Right - Medium
The strategies to handle error ... Whenever we define an error, we should think through whether the caller has any way to handle...
Read more >Best practices for error catching and handling
More videos on YouTube · Be very thorough with your error checking · Check for errors first · Handle errors at the first...
Read more >Clean Code and the Art of Exception Handling - Toptal
Exception Handling : It's a Good Thing · Always create your own ApplicationError hierarchy · Never rescue Exception · Never rescue more exceptions...
Read more >10 Error Handling Best Practices - CLIMB
1. Don't hide errors from the user · 2. Always log errors · 3. Use exceptions for exceptional cases only · 4. Avoid...
Read more >Error monitoring and exception handling in large-scale ...
A solution to handle unhandled exceptions with error monitoring · : Prioritize errors/exceptions found on production servers over those found on ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fwiw, you can just do:
And:
See https://github.com/jakearchibald/idb#shortcuts-to-getset-from-an-object-store.
Yep, it’s all correct, it’s just avoiding some of the shortcuts.
You don’t need to 😄
Yep, although you don’t really need the
await
there. See this for details https://jakearchibald.com/2017/await-vs-return-vs-return-await/.Using the shortcut above:
I’m closing this issue, but feel free to ask follow-up questions.
I’m not really familiar enough with the push API, sorry.