{"record":{"id":"9756097dd3ab8c97","repo":"cloudflare/cloudflared","slug":"failed-to-fetch-page-server-returned-d","errorCode":null,"errorMessage":"Failed to fetch page. Server returned: %d","messagePattern":"Failed to fetch page\\. Server returned: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cfapi/base_client.go","lineNumber":180,"sourceCode":"\t}\n\treturn fullResponse, nil\n}\n\nfunc fetchPage[T any](requestFn func(int) (*http.Response, error), page int) (*response, []*T, error) {\n\tpageResp, err := requestFn(page)\n\tif err != nil {\n\t\treturn nil, nil, errors.Wrap(err, \"REST request failed\")\n\t}\n\tdefer pageResp.Body.Close()\n\tif pageResp.StatusCode == http.StatusOK {\n\t\tenvelope, err := parseResponseEnvelope(pageResp.Body)\n\t\tif err != nil {\n\t\t\treturn nil, nil, err\n\t\t}\n\t\tvar parsedRspBody []*T\n\t\treturn envelope, parsedRspBody, parseResponseBody(envelope, &parsedRspBody)\n\t}\n\treturn nil, nil, errors.New(fmt.Sprintf(\"Failed to fetch page. Server returned: %d\", pageResp.StatusCode))\n}\n\ntype response struct {\n\tSuccess    bool            `json:\"success,omitempty\"`\n\tErrors     []apiError      `json:\"errors,omitempty\"`\n\tMessages   []string        `json:\"messages,omitempty\"`\n\tResult     json.RawMessage `json:\"result,omitempty\"`\n\tPagination Pagination      `json:\"result_info,omitempty\"`\n}\n\ntype Pagination struct {\n\tCount      int `json:\"count,omitempty\"`\n\tPage       int `json:\"page,omitempty\"`\n\tPerPage    int `json:\"per_page,omitempty\"`\n\tTotalCount int `json:\"total_count,omitempty\"`\n}\n\nfunc (r *response) checkErrors() error {","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/cfapi/base_client.go#L162-L198","documentation":"fetchPage returns this error when fetching a paginated result page yields an unexpected HTTP status that is neither a successful response nor one of the mapped sentinel codes. The message embeds the raw status code so the developer can see exactly what the server returned. It effectively means the pagination loop hit an unrecognized or failed server response.","triggerScenarios":"Calling any paginated listing API (e.g. ListTunnels) where the server responds with a status other than 200 and the codes handled by statusCodeToError (401/400/404 etc.) — e.g. 500, 502, 503, 429 from Cloudflare.","commonSituations":"Cloudflare API incidents or maintenance windows; rate limiting (429) during bulk listings; proxies/CDNs injecting error pages; very large account listings triggering server errors.","solutions":["Read the embedded status code: 429/5xx warrant a retry with backoff, 4xx indicates request problems","Add retry-with-backoff around the listing call for 5xx/429 statuses","Check the Cloudflare status page for API incidents if failures persist","Log the response body (if available) for statuses not mapped to sentinels"],"exampleFix":"// before\ntunnels, err := client.ListTunnels(ctx, accountTag)\nif err != nil {\n    return err\n}\n// after\ntunnels, err := client.ListTunnels(ctx, accountTag)\nif err != nil {\n    if retriable(err) { // e.g. status 429 or 5xx in message\n        time.Sleep(backoff)\n        tunnels, err = client.ListTunnels(ctx, accountTag)\n    }\n    if err != nil {\n        return err\n    }\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := doList(ctx)\nif err != nil {\n    var status int\n    if n, _ := fmt.Sscanf(err.Error(), \"Failed to fetch page. Server returned: %d\", &status); n == 1 && (status == 429 || status >= 500) {\n        // exponential backoff retry\n    }\n}","preventionTips":["Add retry with exponential backoff and jitter around paginated list calls","Respect Retry-After on 429 responses","Monitor Cloudflare status for API incidents","Keep page sizes modest for very large accounts"],"tags":["http","api","pagination","cloudflare"],"backgroundTag":"http-error-response","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}