Skip to content

fix(ui): add error state handling for core API calls - #705

Open
Saloni3494 wants to merge 1 commit into
containers:mainfrom
Saloni3494:fix/api-error-states
Open

fix(ui): add error state handling for core API calls#705
Saloni3494 wants to merge 1 commit into
containers:mainfrom
Saloni3494:fix/api-error-states

Conversation

@Saloni3494

Copy link
Copy Markdown

What changed

  • Added an error state to the useBlogPosts custom hook to catch and expose API failures.
  • Updated the fetchData function to explicitly check rawData.ok so that HTTP error responses (like 404s or 429 Rate Limits) correctly throw and trigger the error state.
  • Updated BlogArticlesList/index.tsx to conditionally render a clean fallback UI ("Failed to load the latest blog posts. Please check back later.") if the error state is truthy.

Why this change is needed

Currently, the dynamic data fetch for the latest blog posts on the Homepage and Features page fails silently if there is a network issue or if the WordPress API is unreachable. This leaves the user with an incomplete page and no indication of what went wrong.

By handling these failure states and providing a fallback message, we improve the overall resilience of the UI and ensure the site doesn't feel broken during unexpected network/API disruptions. The fallback UI preserves the SectionHeader to maintain the existing layout structure without causing jarring layout shifts.

Testing

  • Manually verified by simulating a failed network request (modifying the fetch URL to an invalid endpoint) and confirming the fallback UI renders correctly.
  • Verified that yarn typecheck passing logic is unaffected by the new hook return type.
  • yarn build succeeds.

Fixes: #595

Checklist

  • Certify you wrote the patch or otherwise have the right to pass it on as an open-source patch by signing all commits. (git commit -s). The author email must match the sign-off email address.
  • Referenced issues using Fixes: #00000 in the commit message.
  • PR description, commit message, and GitHub comments are human-written, per the LLM Policy.

Fixes: containers#595
Signed-off-by: Saloni Tanmor <saloni.tanmor1@gmail.com>
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.

[Bug] Missing Error State Handling for API Fetch on Core Pages

1 participant