{"record":{"id":"5536828cd720baad","repo":"jeessy2/ddns-go","slug":"dnsla-w-553682","errorCode":null,"errorMessage":"请求 dnsla 失败: %w","messagePattern":"请求 dnsla 失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dns/dnsla.go","lineNumber":230,"sourceCode":"func (dnsla *Dnsla) request(method, apiAddr string, values []byte) (body []byte, err error) {\n\treq, err := http.NewRequest(\n\t\tmethod,\n\t\tapiAddr,\n\t\tbytes.NewReader(values),\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"创建 dnsla 请求失败: %w\", err)\n\t}\n\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\"","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/jeessy2/ddns-go/blob/5874c2e6667c69357ab95079421131104bd3fcae/dns/dnsla.go#L212-L248","documentation":"After building the dnsla request, request() sends it with the package httpClient. Any transport-level failure (DNS resolution, TCP connect, TLS handshake, timeout, context cancellation) is wrapped as 请求 dnsla 失败 with the underlying error via %w. It means the HTTP exchange never completed, not that dnsla returned a bad status.","triggerScenarios":"create/modify -> request -> client.Do fails: dnsla API host unreachable, DNS failure, network outage, TLS certificate problem, or configured client timeout exceeded.","commonSituations":"No internet or firewall blocking the API host; dnsla API domain changed or is blocked in your region; proxy required but not configured; slow network triggering httpClient.Timeout; system clock skew breaking TLS.","solutions":["Inspect the wrapped %w error to distinguish DNS vs connect vs TLS vs timeout","Test reachability: curl -v https://<apiAddr> from the host running the app","Check DNS/hosts, firewall rules, and proxy settings (HTTP_PROXY/HTTPS_PROXY) on the host","Retry with backoff for transient network failures; increase httpClient.Timeout if requests are slow"],"exampleFix":"// before\nresp, err := client.Do(req)\nif err != nil {\n  return nil, fmt.Errorf(\"请求 dnsla 失败: %w\", err)\n}\n// after\nresp, err := client.Do(req)\nif err != nil {\n  var netErr net.Error\n  if errors.As(err, &netErr) && netErr.Timeout() {\n    return nil, fmt.Errorf(\"请求 dnsla 超时: %w\", err)\n  }\n  return nil, fmt.Errorf(\"请求 dnsla 失败: %w\", err)\n}","handlingStrategy":"retry","validationCode":"// pre-flight connectivity check\nconn, err := net.DialTimeout(\"tcp\", host+\":443\", 3*time.Second)\nif err != nil {\n  return fmt.Errorf(\"无法连接 dnsla API 主机 %s: %w\", host, err)\n}\nconn.Close()","typeGuard":"func isTimeoutErr(err error) bool {\n  var ne net.Error\n  return errors.As(err, &ne) && ne.Timeout()\n}","tryCatchPattern":"resp, err := client.Do(req)\nif err != nil {\n  var ne net.Error\n  if errors.As(err, &ne) && ne.Timeout() {\n    return nil, fmt.Errorf(\"请求 dnsla 超时: %w\", err)\n  }\n  return nil, fmt.Errorf(\"请求 dnsla 失败: %w\", err) // retry transient failures with backoff\n}","preventionTips":["Set a sane httpClient.Timeout and honor it in retry logic","Retry transient network errors with exponential backoff and jitter","Check DNS/firewall/proxy configuration on the host before debugging the library","Monitor clock sync (NTP) to avoid TLS handshake failures"],"tags":["go","network","http","dns","timeout"],"backgroundTag":"http-request-failed","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"}