{"record":{"id":"6fd75ae645965734","repo":"jeessy2/ddns-go","slug":"paginated-query-api-error-at-page-d-s","errorCode":null,"errorMessage":"paginated query API error at page %d: %s","messagePattern":"paginated query API error at page (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dns/hipmdnsmgr.go","lineNumber":290,"sourceCode":"\t\tif d.Name == domainName {\n\t\t\treturn d.ID, nil\n\t\t}\n\t}\n\n\t// Method 2: If keyword query not found, use list matching as fallback (compatible with old API)\n\t// Paginate through all domains to find the target\n\tconst pageSize = 100\n\tcurrentPage := 1\n\n\tfor {\n\t\tpath := fmt.Sprintf(\"/domains?page=%d&pageSize=%d\", currentPage, pageSize)\n\t\tapiResp, err := h.request(baseURL, apiToken, \"GET\", path, nil)\n\t\tif err != nil {\n\t\t\treturn 0, fmt.Errorf(\"paginated query failed at page %d: %w\", currentPage, err)\n\t\t}\n\n\t\tif apiResp.Code != 0 {\n\t\t\treturn 0, fmt.Errorf(\"paginated query API error at page %d: %s\", currentPage, apiResp.Msg)\n\t\t}\n\n\t\t// Parse response with smart format detection\n\t\tvar pageDomains []DnsMgrDomain\n\t\tvar total int\n\n\t\tvar rawData interface{}\n\t\tif err := json.Unmarshal(apiResp.Data, &rawData); err == nil {\n\t\t\tswitch v := rawData.(type) {\n\t\t\tcase []interface{}:\n\t\t\t\tjsonData, _ := json.Marshal(v)\n\t\t\t\tjson.Unmarshal(jsonData, &pageDomains)\n\t\t\tcase map[string]interface{}:\n\t\t\t\tif listData, ok := v[\"list\"]; ok {\n\t\t\t\t\tjsonData, _ := json.Marshal(listData)\n\t\t\t\t\tjson.Unmarshal(jsonData, &pageDomains)\n\t\t\t\t}\n\t\t\t\tif totalData, ok := v[\"total\"]; ok {","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/jeessy2/ddns-go/blob/5874c2e6667c69357ab95079421131104bd3fcae/dns/hipmdnsmgr.go#L272-L308","documentation":"getDomainID paginates GET /domains looking for the domain whose name matches domainName. When the provider response carries a non-zero business Code, the page-level query itself is considered failed and this error wraps the provider's Msg with the page number, aborting the lookup for updateRecord.","triggerScenarios":"The DNS provider returns apiResp.Code != 0 while fetching one of the domain-list pages during getDomainID (e.g. auth/token rejection, rate limit, server-side error on that page).","commonSituations":"Expired or revoked API token, provider rate limiting during the paged scan (up to 10 pages), transient provider outage, or an account that no longer has domain-list permission.","solutions":["Log/review apiResp.Msg for the real provider reason and fix the underlying cause (token, permissions, quota)","Verify the API token is valid and not expired by making a simple provider call","Check provider status page for an outage and retry later","Add backoff/retry around the paginated scan to survive transient rate limits"],"exampleFix":"// before\nreturn 0, fmt.Errorf(\"paginated query API error at page %d: %s\", currentPage, apiResp.Msg)\n// after\nreturn 0, fmt.Errorf(\"paginated query API error at page %d: %s (code=%d)\", currentPage, apiResp.Msg, apiResp.Code)","handlingStrategy":"try-catch","validationCode":"// Go: verify token works before paginating\nif err := pingProvider(baseURL, apiToken); err != nil {\n    return fmt.Errorf(\"provider unreachable or token invalid: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"id, err := mgr.getDomainID(baseURL, token, domain)\nif err != nil {\n    if strings.Contains(err.Error(), \"API error at page\") {\n        // provider rejected a page; inspect msg, backoff and retry\n    }\n    return err\n}","preventionTips":["Validate the API token with a cheap call before running update flows","Add retry/backoff around paginated provider scans","Log apiResp.Code and Msg for diagnostics","Monitor token expiry and refresh proactively"],"tags":["dns","api","pagination","http"],"backgroundTag":"dns-provider-api-rejected","analyzedSha":"5874c2e6667c69357ab95079421131104bd3fcae","analyzedAt":"2026-09-03T15:41:16.799Z","contentChangedAt":"2026-09-03T15:41:16.799Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}