{"record":{"id":"4c2f18c2dda5c5e0","repo":"jeessy2/ddns-go","slug":"dnsla-d-s","errorCode":null,"errorMessage":"dnsla 请求失败，状态码: %d, 响应: %s","messagePattern":"dnsla 请求失败，状态码: (.+?), 响应: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dns/dnsla.go","lineNumber":239,"sourceCode":"\t// 设置自定义 Headers\n\tbyteBuff := []byte(dnsla.DNS.ID + \":\" + dnsla.DNS.Secret)\n\ttoken := \"Basic \" + base64.StdEncoding.EncodeToString(byteBuff)\n\treq.Header.Set(\"Authorization\", token)\n\treq.Header.Set(\"Content-Type\", \"application/json;charset=utf-8\")\n\t// 4. 发送请求\n\tclient := dnsla.httpClient\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"请求 dnsla 失败: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tbody, err = io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"读取 dnsla 响应失败: %w\", err)\n\t}\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"dnsla 请求失败，状态码: %d, 响应: %s\", resp.StatusCode, string(body))\n\t}\n\treturn body, nil\n}\n\n// 获得域名记录列表\nfunc (dnsla *Dnsla) getRecordList(domain *config.Domain, typ string) (result []byte, err error) {\n\trecordTypeInt := \"1\"\n\tif typ == \"AAAA\" {\n\t\trecordTypeInt = \"28\"\n\t}\n\tparams := domain.GetCustomParams()\n\tparams.Set(\"domain\", domain.DomainName)\n\tparams.Set(\"host\", domain.GetSubDomain())\n\tparams.Set(\"type\", recordTypeInt)\n\tparams.Set(\"pageIndex\", \"1\")\n\tparams.Set(\"pageSize\", \"999\")\n\n\turl := recordList + \"?\" + params.Encode()","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/jeessy2/ddns-go/blob/5874c2e6667c69357ab95079421131104bd3fcae/dns/dnsla.go#L221-L257","documentation":"If the dnsla API responds but with a non-200 status, request() returns this error embedding the status code and the raw response body. It means dnsla received and answered the request but rejected it — an application-level API error (auth, rate limit, bad parameters), not a transport failure.","triggerScenarios":"create/modify -> request gets a response with StatusCode != http.StatusOK: invalid/expired Basic-auth credentials (DNS.ID/DNS.Secret), rate limiting (429), invalid record parameters (400/422), or server-side 5xx.","commonSituations":"Wrong or rotated dnsla API ID/Secret; exceeding API rate limits; malformed record data the API rejects; dnsla service outage returning 5xx; account permission issues.","solutions":["Read the 响应 body in the error — dnsla usually explains the rejection (auth error, param error)","Verify dnsla.DNS.ID and DNS.Secret are correct and not expired; regenerate credentials if needed","Handle 429 by backing off and retrying; check the API rate-limit docs","Validate record parameters (domain, type, value, TTL) against the dnsla API spec for 4xx errors","For 5xx, treat as server-side: retry later and check dnsla service status"],"exampleFix":"// before\nif resp.StatusCode != http.StatusOK {\n  return nil, fmt.Errorf(\"dnsla 请求失败，状态码: %d, 响应: %s\", resp.StatusCode, string(body))\n}\n// after\nif resp.StatusCode != http.StatusOK {\n  if resp.StatusCode == http.StatusTooManyRequests {\n    time.Sleep(retryAfter) // honor Retry-After header\n    return dnsla.request(method, apiAddr, values)\n  }\n  return nil, fmt.Errorf(\"dnsla 请求失败，状态码: %d, 响应: %s\", resp.StatusCode, string(body))\n}","handlingStrategy":"fallback","validationCode":"// verify credentials are set and non-empty before calling the API\nif dnsla.DNS.ID == \"\" || dnsla.DNS.Secret == \"\" {\n  return errors.New(\"dnsla 凭证未配置\")\n}","typeGuard":"null","tryCatchPattern":"if resp.StatusCode != http.StatusOK {\n  switch {\n  case resp.StatusCode == http.StatusUnauthorized:\n    return nil, errors.New(\"dnsla 认证失败，请检查 ID/Secret\")\n  case resp.StatusCode == http.StatusTooManyRequests:\n    return nil, retryLater(fmt.Errorf(\"dnsla 限流: %s\", string(body)))\n  default:\n    return nil, fmt.Errorf(\"dnsla 请求失败，状态码: %d, 响应: %s\", resp.StatusCode, string(body))\n  }\n}","preventionTips":["Read the response body included in the error — it states the API's reason","Keep dnsla credentials current; rotate and re-test after changes","Back off on 429 and honor Retry-After headers","Validate record payloads against the dnsla API docs to avoid 4xx rejections","Watch for 5xx patterns and add circuit-breaker/retry-later behavior"],"tags":["go","http","api","dns","status-code"],"backgroundTag":"api-non-200-response","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"}