Fix Cases Page API Connection Issue - apiRequest BASE_URL Prepending#26
Fix Cases Page API Connection Issue - apiRequest BASE_URL Prepending#26
Conversation
Co-authored-by: teoat <68715844+teoat@users.noreply.github.com>
Co-authored-by: teoat <68715844+teoat@users.noreply.github.com>
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||
| if (!response.ok) { | ||
| await response.text().catch(() => 'Unknown error'); |
There was a problem hiding this comment.
Suggestion: Include API error body in exception
New proposed code:
if (!response.ok) {
- await response.text().catch(() => 'Unknown error');
- throw new Error(`API request failed: ${response.status} ${response.statusText}`);
+ const errorBody = await response.text().catch(() => 'Could not read error body');
+ throw new Error(`API request failed: ${response.status} ${response.statusText} - ${errorBody}`);
}|
try again |
|
@copilot retry and come up with screenshot and layout design as specified in the @docs/frontend/pages/ for cases page |
Screenshot of the Cases page successfully loading with the fix applied: The page now correctly:
The layout matches the specification in |

Description
Fixed a critical bug where the cases page and other components failed to load data because the
apiRequestfunction was not prepending the base API URL to relative URLs. This caused all API calls usingapiRequestto be sent to the frontend server instead of the backend API server.Related Issue
Closes #
Type of Change
Changes Made
apiRequestfunction infrontend/src/lib/api.tsto prependVITE_API_URL(or default/api/v1) to relative URLsfrontend/.env.exampleto include correct API URL with/api/v1path (http://localhost:8000/api/v1)frontend/CASES_PAGE_FIX.mdexplaining the issue, fix, and setup instructionsTesting
Test Coverage:
Test Commands Run:
Manual Testing Performed:
/cases) loads and displays case data from backendapiRequestcan now connect to backend APIImpact Assessment
Breaking Changes:
Performance Impact:
Security Considerations:
Components Fixed:
This fix resolves API connection issues for ALL components using
apiRequest:/casesendpoint/cases/{id}endpointScreenshots (if applicable)
Cases Page Successfully Loading:
The screenshot shows:
/api/v1/cases)Accessibility
Documentation
frontend/CASES_PAGE_FIX.mdwith detailed explanation of issue and fixChecklist
Code Quality:
npm run lintorpoetry run ruff check .)npm run buildorpoetry run mypy app/)Testing:
Dependencies:
Git Hygiene:
CI/CD:
For AI Coding Agents
AI Agent Confidence:
Reviewer Notes
Focus Areas:
apiRequestfunction correctly handles both relative and absolute URLsSetup Instructions for Testing:
Post-Merge Actions
For Reviewers:
.envfile is created from.env.examplein production deployments.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
PR Type
Bug fix, Documentation
Description
Fixed
apiRequestfunction to prepend base API URL for relative URLsUpdated
.env.examplewith correct API URL including/api/v1pathAdded comprehensive documentation for cases page fix
Fixed API endpoint calls in CaseList and CaseDetail components
Diagram Walkthrough
File Walkthrough
api.ts
Prepend base URL to relative API requestsfrontend/src/lib/api.ts
VITE_API_URLto relative URLsURLs
fetchcall to usefullUrlinstead of rawurlparameterCaseList.tsx
Fix cases endpoint URL constructionfrontend/src/pages/CaseList.tsx
/?and using templateliteral
CaseDetail.tsx
Add POST method to prediction requestfrontend/src/pages/CaseDetail.tsx
method: 'POST'option to ai-risk-prediction API request.env.example
Update API URL with required pathfrontend/.env.example
VITE_API_URLto include/api/v1path/api/v1pathCASES_PAGE_FIX.md
Add cases page fix documentationfrontend/CASES_PAGE_FIX.md
cause