Skip to content

Standardize frontend API call pattern (eliminate ad-hoc fetch in components) #101

@nv78

Description

@nv78

Problem

API calls are made three different ways across the frontend:

  1. Redux async thunks — used in UserSlice.js, ChatSlice.js
  2. Direct fetcher() calls — scattered inline in component bodies
  3. Custom hooksuseChatHistory.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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions