From c96c7855c6578cb3eb6cf749fabfb9d2b1023dfb Mon Sep 17 00:00:00 2001 From: saravanakumardb1 Date: Tue, 31 Mar 2026 00:51:16 -0700 Subject: [PATCH] fix(mobile): add error handling to store hydrate methods - notes-store: wrap hydrate() and openNote() in try/catch to prevent isLoading stuck true - inbox-store: wrap hydrate() in try/catch to prevent isLoading stuck true on API failure - openNote falls back to cached list note when detail fetch fails --- mobile/src/store/inbox-store.ts | 16 ++++++++++------ mobile/src/store/notes-store.ts | 16 ++++++++++++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/mobile/src/store/inbox-store.ts b/mobile/src/store/inbox-store.ts index 9ff0991..cc44e79 100644 --- a/mobile/src/store/inbox-store.ts +++ b/mobile/src/store/inbox-store.ts @@ -46,12 +46,16 @@ export const useInboxStore = create((set, get) => ({ isLoading: false, async hydrate() { set({ isLoading: true }); - const [approvals, activity] = await Promise.all([listApprovalQueue(), listActivityFeed()]); - set({ - approvals: approvals.map(toApprovalItem), - activity: activity.map(toActivityItem), - isLoading: false, - }); + try { + const [approvals, activity] = await Promise.all([listApprovalQueue(), listActivityFeed()]); + set({ + approvals: approvals.map(toApprovalItem), + activity: activity.map(toActivityItem), + isLoading: false, + }); + } catch { + set({ isLoading: false }); + } }, async approve(id: string, reviewNote?: string) { const current = get().approvals.find((item) => item.id === id); diff --git a/mobile/src/store/notes-store.ts b/mobile/src/store/notes-store.ts index 0ee48fd..76c94ac 100644 --- a/mobile/src/store/notes-store.ts +++ b/mobile/src/store/notes-store.ts @@ -30,8 +30,12 @@ export const useNotesStore = create((set, get) => ({ isLoading: false, async hydrate() { set({ isLoading: true }); - const notes = await listNotes(); - set({ notes, isLoading: false }); + try { + const notes = await listNotes(); + set({ notes, isLoading: false }); + } catch { + set({ isLoading: false }); + } }, async openNote(id: string) { set({ isLoading: true }); @@ -41,8 +45,12 @@ export const useNotesStore = create((set, get) => ({ return; } - const note = await getNote(id, current.workspaceId); - set({ selectedNote: note, isLoading: false }); + try { + const note = await getNote(id, current.workspaceId); + set({ selectedNote: note, isLoading: false }); + } catch { + set({ selectedNote: current, isLoading: false }); + } }, async saveDraft(workspaceId: string | null, title: string, body: string) { if (!workspaceId) {