Skip to content

refactor: Reafctor MACAE-V4 UI#844

Open
NirajC-Microsoft wants to merge 10 commits intodev-v4from
psl-macae-uirefactor
Open

refactor: Reafctor MACAE-V4 UI#844
NirajC-Microsoft wants to merge 10 commits intodev-v4from
psl-macae-uirefactor

Conversation

@NirajC-Microsoft
Copy link
Contributor

Purpose

This pull request refactors the frontend API layer to centralize HTTP logic, error handling, and authentication header injection. It introduces a singleton httpClient with interceptors, removes duplicated header and token logic from individual API calls, and adds a utility module for error and retry handling. Additionally, it cleans up unnecessary logging and streamlines request caching and deduplication.

Centralized HTTP client and authentication:

  • Introduced a singleton httpClient in httpClient.ts, which wraps all API calls with automatic authentication header injection, uniform error handling, and request/response interceptors. This eliminates the need for manual headerBuilder and localStorage.getItem('token') calls across the codebase. (src/frontend/src/api/httpClient.ts, src/frontend/src/api/httpClient.tsR1-R246)
  • Refactored apiClient.tsx to use the new httpClient, simplifying the API interface and ensuring runtime base URL synchronization. (src/frontend/src/api/apiClient.tsx, src/frontend/src/api/apiClient.tsxL1-L103)
  • Removed the headerBuilder function and all related manual header logic from config.tsx. (src/frontend/src/api/config.tsx, src/frontend/src/api/config.tsxL100-L133)

API utility functions:

  • Added apiUtils.ts with centralized helpers for error response construction, retry logic, request deduplication, and caching. This provides a single source of truth for common API patterns. (src/frontend/src/api/apiUtils.ts, src/frontend/src/api/apiUtils.tsR1-R149)
  • Exported the new utilities and httpClient from index.tsx for use throughout the frontend. (src/frontend/src/api/index.tsx, src/frontend/src/api/index.tsxR4-R9)

Logging and error handling cleanup:

  • Removed redundant logging and error messages from apiService.tsx, config.tsx, and TeamSelector.tsx to reduce noise and improve clarity. (src/frontend/src/api/apiService.tsx, [1] [2] [3] [4]; src/frontend/src/api/config.tsx, [5] [6]; src/frontend/src/components/common/TeamSelector.tsx, [7] [8]

These changes make the API layer more maintainable, consistent, and easier to extend for future features.

Does this introduce a breaking change?

  • Yes
  • No

How to Test

  • Get the code
git clone [repo-address]
cd [repo-name]
git checkout [branch-name]
npm install
  • Test the code

What to Check

Verify that the following are valid

  • ...

Other Information

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants