cloudflare/cloudflared · error
Error Parsing page %d
Error message
Error Parsing page %d
What it means
fetchExhaustively paginates through list endpoints page by page; if fetchPage fails for any page it wraps the error with 'Error Parsing page %d'. Any per-page failure (HTTP error, decode failure, unexpected shape) is surfaced with the page number to identify which page broke.
Source
Thrown at cfapi/base_client.go:155
func parseResponseBody(result *response, data interface{}) error {
// At this point we know the API call succeeded, so, parse out the inner
// result into the datatype provided as a parameter.
if err := json.Unmarshal(result.Result, &data); err != nil {
return errors.Wrap(err, "the Cloudflare API response was an unexpected type")
}
return nil
}
func fetchExhaustively[T any](requestFn func(int) (*http.Response, error)) ([]*T, error) {
page := 0
var fullResponse []*T
for {
page += 1
envelope, parsedBody, err := fetchPage[T](requestFn, page)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("Error Parsing page %d", page))
}
fullResponse = append(fullResponse, parsedBody...)
if envelope.Pagination.Count < envelope.Pagination.PerPage || len(fullResponse) >= envelope.Pagination.TotalCount {
break
}
}
return fullResponse, nil
}
func fetchPage[T any](requestFn func(int) (*http.Response, error), page int) (*response, []*T, error) {
pageResp, err := requestFn(page)
if err != nil {
return nil, nil, errors.Wrap(err, "REST request failed")
}
defer pageResp.Body.Close()
if pageResp.StatusCode == http.StatusOK {
envelope, err := parseResponseEnvelope(pageResp.Body)View on GitHub (pinned to 2253eeeb25)
Solutions
- Look at the wrapped inner error to see whether it's an HTTP failure or a decode failure for that page.
- Retry the operation — transient failures mid-pagination are common.
- If rate limited, back off and retry with fewer concurrent API calls.
- Upgrade the library if the inner error indicates an unexpected response shape.
Defensive patterns
Strategy: retry
Try / catch
routes, err := client.ListRoutes(t, filter)
if err != nil {
var perr *pageParseError // inspect wrapped 'Error Parsing page N'
if strings.Contains(err.Error(), "Error Parsing page") {
err = retry(3, backoff, func() error {
var e error
routes, e = client.ListRoutes(t, filter)
return e
})
}
if err != nil { return err }
} Prevention
- Add retry/backoff around paginated list calls.
- Avoid concurrent bulk API calls that trigger rate limits mid-pagination.
- Handle large accounts by ensuring generous HTTP timeouts.
When it happens
Trigger: A specific page of a paginated list (routes, virtual networks) fails: transient HTTP error mid-pagination, rate limiting on later pages, or malformed data on one page.
Common situations: Large accounts with many teamnet routes where later pages hit rate limits or timeouts; network instability during long multi-page fetches.
Understand the failure class
Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.
Related errors
- can't create %s request
- Failed to fetch page. Server returned: %d
- header Key: %s malformed
- Error setting content-length: %w
- failed to create account level endpoint
AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06).
Data as JSON: /api/errors/57beff2f6f89009c.
Report an issue: GitHub.