{"record":{"id":"f74f9b5d59fa186b","repo":"jeessy2/ddns-go","slug":"v-f74f9b","errorCode":null,"errorMessage":"请求失败: %v","messagePattern":"请求失败: %v","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dns/eranet.go","lineNumber":272,"sourceCode":"\n\t// 构造完整URL\n\tbaseURL := \"https://www.eranet.com\"\n\tfullURL := baseURL + apiPath + \"?\" + queryString\n\n\t// 创建HTTP请求\n\treq, err := http.NewRequest(method, fullURL, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"创建请求失败: %v\", err)\n\t}\n\n\t// 设置请求头\n\treq.Header.Set(\"Accept\", \"application/json\")\n\n\t// 发送请求\n\tclient := t.httpClient\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"请求失败: %v\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\t// 读取响应\n\tbody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"读取响应失败: %v\", err)\n\t}\n\n\t// 检查HTTP状态码\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"API请求失败，状态码: %d, 响应: %s\", resp.StatusCode, string(body))\n\t}\n\n\treturn body, nil\n}\n","sourceCodeStart":254,"sourceCodeEnd":289,"githubUrl":"https://github.com/jeessy2/ddns-go/blob/5874c2e6667c69357ab95079421131104bd3fcae/dns/eranet.go#L254-L289","documentation":"Thrown by Eranet.request when client.Do(req) fails — the HTTP request to https://www.eranet.com could not be completed at the transport level. This wraps the net/http error (DNS failure, connection refused/reset, timeout, TLS error), affecting create, modify, and getRecordList.","triggerScenarios":"Any Eranet API call where the network round-trip fails: DNS resolution failure for www.eranet.com, TCP connection refused/reset, request timeout via t.httpClient, TLS handshake failure, or no network connectivity.","commonSituations":"Running ddns-go behind a firewall/proxy that blocks eranet.com; intermittent ISP or DNS outages; overly aggressive httpClient timeout; corporate MITM proxies breaking TLS; transient network flaps during DNS updates.","solutions":["Check basic connectivity to https://www.eranet.com (curl -v) from the host running the program","Check DNS resolution of www.eranet.com on that host","Retry the request — this is often transient; consider adding backoff/retry in create/modify paths","If behind a proxy, configure the proxy for the http.Client; if a timeout was configured, increase it","Verify system time is correct — clock skew causes TLS handshake failures"],"exampleFix":"// before\nresp, err := client.Do(req)\nif err != nil {\n    return nil, fmt.Errorf(\"请求失败: %v\", err)\n}\n// after\nresp, err := client.Do(req)\nif err != nil {\n    return nil, fmt.Errorf(\"请求失败: %w\", err) // retry with backoff at caller\n}","handlingStrategy":"retry","validationCode":"// preflight connectivity check\nresp, err := http.Get(\"https://www.eranet.com\")\nif err != nil {\n    return fmt.Errorf(\"eranet unreachable, check network/DNS/proxy: %w\", err)\n}\nresp.Body.Close()","typeGuard":"var dnsErr *net.DNSError\nif errors.As(err, &dnsErr) {\n    // DNS-level failure vs connection/timeout failure\n}","tryCatchPattern":"body, err := eranetClient.CreateRecord(params)\nif err != nil {\n    if strings.Contains(err.Error(), \"请求失败\") {\n        return retryWithBackoff(3, func() error {\n            _, err = eranetClient.CreateRecord(params)\n            return err\n        })\n    }\n    return err\n}","preventionTips":["Set a sane http.Client timeout (e.g. 10-30s) — not zero, not 1s","Run the ddns client on a host with reliable egress; verify eranet.com isn't firewall-blocked","Configure proxy env vars correctly if operating behind a corporate proxy","Keep system clock synced (NTP) to avoid TLS failures","Implement exponential backoff for transient network errors"],"tags":["network","http","timeout","connectivity","go"],"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"}