{"record":{"id":"7ae22ba85d93db97","repo":"jeessy2/ddns-go","slug":"paginated-record-query-api-error-at-page-d-s","errorCode":null,"errorMessage":"paginated record query API error at page %d: %s","messagePattern":"paginated record query API error at page (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dns/hipmdnsmgr.go","lineNumber":355,"sourceCode":"}\n\n// getRecord Get DNS record\n// Paginate through all records to find the target\nfunc (h *HiPMDnsMgr) getRecord(baseURL, apiToken string, domainID int, subDomain, recordType string) (*DnsMgrRecord, error) {\n\tconst pageSize = 100\n\tcurrentPage := 1\n\n\tfor {\n\t\tpath := fmt.Sprintf(\"/domains/%d/records?page=%d&pageSize=%d&subdomain=%s&type=%s\",\n\t\t\tdomainID, currentPage, pageSize, subDomain, recordType)\n\n\t\tapiResp, err := h.request(baseURL, apiToken, \"GET\", path, nil)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"paginated record query failed at page %d: %w\", currentPage, err)\n\t\t}\n\n\t\tif apiResp.Code != 0 {\n\t\t\treturn nil, fmt.Errorf(\"paginated record query API error at page %d: %s\", currentPage, apiResp.Msg)\n\t\t}\n\n\t\tvar recordList DnsMgrRecordList\n\t\tif err := json.Unmarshal(apiResp.Data, &recordList); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to parse record list: %w\", err)\n\t\t}\n\n\t\t// Find matching record in current page\n\t\tfor _, r := range recordList.List {\n\t\t\tif r.Name == subDomain && r.Type == recordType {\n\t\t\t\treturn &r, nil\n\t\t\t}\n\t\t}\n\n\t\t// Check if we've reached the end\n\t\tif len(recordList.List) < pageSize || (recordList.Total > 0 && currentPage*pageSize >= recordList.Total) {\n\t\t\tbreak\n\t\t}","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/jeessy2/ddns-go/blob/5874c2e6667c69357ab95079421131104bd3fcae/dns/hipmdnsmgr.go#L337-L373","documentation":"When the provider answers a records page with a non-zero business Code, getRecord treats the page as failed and surfaces the provider's Msg tagged with the page number. The record search for updateRecord aborts.","triggerScenarios":"apiResp.Code != 0 on a GET /domains/{id}/records page — invalid domainID, token lacking record-read permission, rate limit, or provider-side error on that specific page.","commonSituations":"Stale domainID from a domain deleted/recreated, token permission changes, provider rate limiting during large record scans.","solutions":["Read apiResp.Msg in the error string for the exact provider reason","Confirm the domainID (from getDomainID) is still valid on the provider","Verify token permissions for record read access","Retry after backoff if the Msg indicates throttling"],"exampleFix":"// before\nreturn nil, fmt.Errorf(\"paginated record query API error at page %d: %s\", currentPage, apiResp.Msg)\n// after\nreturn nil, fmt.Errorf(\"paginated record query API error at page %d (code=%d): %s\", currentPage, apiResp.Code, apiResp.Msg)","handlingStrategy":"try-catch","validationCode":"// Go: re-validate domainID before record scan\nif domainID <= 0 { return errors.New(\"invalid domainID; refresh via getDomainID\") }","typeGuard":null,"tryCatchPattern":"rec, err := mgr.getRecord(baseURL, token, domainID, sub, rtype)\nif err != nil && strings.Contains(err.Error(), \"API error at page\") {\n    // parse provider msg; if code indicates stale domain, refresh domainID and retry once\n    domainID, derr := mgr.getDomainID(baseURL, token, domain)\n    if derr == nil { rec, err = mgr.getRecord(baseURL, token, domainID, sub, rtype) }\n}","preventionTips":["Refresh domainID before each update run instead of caching it","Log full Code+Msg from provider responses","Back off when Msg indicates rate limiting","Keep token permissions aligned with record read access"],"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"}