Improve Firebase getDataOnce handling - #2
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| export async function getDataOnce(path) { | ||
| try { | ||
| const snapshot = await get(child(ref(db), path)) | ||
|
|
||
| if (!snapshot?.exists()) | ||
| return false | ||
|
|
||
| return snapshot.val() | ||
| } | ||
| catch (error) { | ||
| console.error(error?.message ?? error) | ||
| throw error |
There was a problem hiding this comment.
Avoid rejecting from getDataOnce without caller handling
The new catch block rethrows Firebase errors (getDataOnce now rejects instead of resolving a falsy value). Existing callers such as store/currencies/actions.ts:initCurrencies and store/lang/actions.js:initDbLang rely on the old behaviour where failures simply returned undefined and the code fell back to defaults or alternate data sources. Because those dispatches are not awaited or wrapped in try/catch, any transient database error will now short‑circuit the actions and surface as unhandled promise rejections, leaving currencies/lang uninitialized. Either revert to resolving a sentinel value or update the call sites to catch and handle the rejection.
Useful? React with 👍 / 👎.
Summary
getDataOnceto usesnapshot.exists()and throw on Firebase errorsTesting
Codex Task