Problem
API calls are made three different ways across the frontend:
- Redux async thunks — used in
UserSlice.js, ChatSlice.js
- Direct
fetcher() calls — scattered inline in component bodies
- Custom hooks —
useChatHistory.js and similar
This inconsistency makes it hard to add cross-cutting concerns (auth errors, loading states, retry logic) in one place.
Solution
Standardize on Redux async thunks for all server state (data that persists across components), and custom hooks for local/ephemeral fetch operations. Remove direct fetcher() calls from component bodies.
Add a shared error handler in the Redux store's middleware that catches 401s and dispatches a logout action.
Why
- Centralised loading/error state visible across the component tree
- Auth errors handled once instead of in every component
- Easier to add request deduplication and caching later
Problem
API calls are made three different ways across the frontend:
UserSlice.js,ChatSlice.jsfetcher()calls — scattered inline in component bodiesuseChatHistory.jsand similarThis inconsistency makes it hard to add cross-cutting concerns (auth errors, loading states, retry logic) in one place.
Solution
Standardize on Redux async thunks for all server state (data that persists across components), and custom hooks for local/ephemeral fetch operations. Remove direct
fetcher()calls from component bodies.Add a shared error handler in the Redux store's middleware that catches 401s and dispatches a logout action.
Why