-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Description
Description
The fetchData function in src/plugins/plugin-json-rpc.ts does not check HTTP response status codes before parsing JSON. As a result, error responses (404, 500, etc.) are treated as successful responses, which can lead to incorrect data processing and build failures.
Current Behavior
async function fetchData(url: string, name: string): Promise<ResponseItem> {
try {
const response = await fetch(url, { method: 'GET' })
const data = await response.json() // ❌ No status check
return { name, data, error: false }
} catch (error) {
return { name, data: null, error: true }
}
}Problems:
- If the API returns 404, 500, or any non-2xx status, the error response body is parsed as JSON
- The function returns
error: falseeven when the HTTP request failed - Error responses are treated as valid data
- Network errors are caught, but HTTP errors are not
Expected Behavior
The function should:
- Check
response.okorresponse.statusbefore parsing JSON - Return proper error information for HTTP errors
- Distinguish between network errors and HTTP errors
- Only parse JSON when the response is successful
Impact
Severity: High
Affected Areas:
- Build process (used during Docusaurus build to fetch API specs)
- Dynamic sidebar generation
- Route generation for JSON-RPC methods
- Production deployments when external APIs are unavailable
Potential Consequences:
- Build succeeds but with incorrect/missing API documentation
- Silent failures when APIs are down
- Incorrect routes generated from error responses
- Difficult to debug production issues
Metadata
Metadata
Assignees
Labels
No labels