Skip to content

Missing HTTP Status Check in fetchData Function #2597

@subhamkumarr

Description

@subhamkumarr

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:

  1. If the API returns 404, 500, or any non-2xx status, the error response body is parsed as JSON
  2. The function returns error: false even when the HTTP request failed
  3. Error responses are treated as valid data
  4. Network errors are caught, but HTTP errors are not

Expected Behavior

The function should:

  1. Check response.ok or response.status before parsing JSON
  2. Return proper error information for HTTP errors
  3. Distinguish between network errors and HTTP errors
  4. 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions