Skip to content

Add HTTP error status validation to API fetch calls - #10

Closed
Blb3D with Copilot wants to merge 2 commits into
claude/project-pivot-checklist-011CUhWCe2VxLH4niJGCiMqhfrom
copilot/sub-pr-8-again
Closed

Add HTTP error status validation to API fetch calls#10
Blb3D with Copilot wants to merge 2 commits into
claude/project-pivot-checklist-011CUhWCe2VxLH4niJGCiMqhfrom
copilot/sub-pr-8-again

Conversation

Copilot AI commented Nov 1, 2025

Copy link
Copy Markdown
Contributor

All fetch calls were calling .json() without checking response.ok, causing unhandled promise rejections on non-200 status codes.

Changes

  • Added response.ok validation before parsing JSON for all four API endpoints:

    • /api/usage
    • /api/costs/summary
    • /api/models/pricing
    • /api/recommendations
  • Errors now include HTTP status code and status text for debugging

Example

const usageRes = await fetch(`${API_BASE_URL}/api/usage?limit=100`);
if (!usageRes.ok) {
  throw new Error(`Failed to fetch usage data: ${usageRes.status} ${usageRes.statusText}`);
}
const usageData = await usageRes.json();

Errors are caught by existing try-catch and displayed to users via the error banner component.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: Blb3D <179528688+Blb3D@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP: Address feedback from PR #8 on LLMscope cost dashboard transformation Add HTTP error status validation to API fetch calls Nov 1, 2025
Copilot AI requested a review from Blb3D November 1, 2025 17:51
@Blb3D Blb3D closed this Nov 2, 2025
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