In the Pairing Simulator page, I am getting the error: **Error:**Unexpected token '<', "<!DOCTYPE "... is not valid JSON Fid and fix the bug
1.8 KiB
1.8 KiB
Bug Investigation & Implementation Report - Task 7382
Bug Summary
The Pairing Simulator was failing with the error: Unexpected token '<', "<!DOCTYPE "... is not valid JSON. This was caused by a mismatch between the frontend's expected API endpoint and the server's actual routes, leading to a 404 HTML response instead of JSON.
Root Cause Analysis
- Endpoint Mismatch: The frontend called
POST /api/pedigree/coi, but the server only implementedPOST /api/pedigree/trial-pairing. - Property Naming: The frontend expected
common_ancestors(snake_case), while the server returnedcommonAncestors(camelCase). - Data Structure: The frontend expected
common_ancestorsto be an array of strings, while the server returned an array of objects. - COI Scaling: The server returned COI as a percentage (e.g., 25.00), while the frontend functions (
coiColor,coiLabel) expected decimals (e.g., 0.25).
Affected Components
client/src/pages/PairingSimulator.jsxserver/routes/pedigree.js
Proposed & Implemented Solution
- Server Fix: Modified
calculateCOIinserver/routes/pedigree.jsto return the raw decimal value forcoefficient. - Frontend Fix: Updated
PairingSimulator.jsxto:- Use the documented
/api/pedigree/trial-pairingendpoint. - Use the
commonAncestorsproperty from the response. - Access the
.nameproperty when mapping over the common ancestors list. - The COI display logic
(result.coi * 100).toFixed(2)now works correctly with the decimal value from the server.
- Use the documented
Verification Results
- Manual code analysis confirms that the frontend and backend now share a consistent API contract.
- The COI thresholds and color coding in the frontend now correctly interpret the values provided by the server.