jeessy2/ddns-go · error

请求 dnsla 记录列表失败: %w

Error message

请求 dnsla 记录列表失败: %w

What it means

This error is returned when the HTTP client fails to execute the GET request to the dnsla record-list API, e.g. DNS resolution failure, connection refused/timeout, or TLS errors. It wraps the underlying net/http error so the root cause is available via errors.Unwrap. It means the request never reached dnsla or no response was received.

Source

Thrown at dns/dnsla.go:272

	params.Set("pageIndex", "1")
	params.Set("pageSize", "999")

	url := recordList + "?" + params.Encode()
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return nil, fmt.Errorf("创建 dnsla 记录列表请求失败: %w", err)
	}

	byteBuff := []byte(dnsla.DNS.ID + ":" + dnsla.DNS.Secret)
	token := "Basic " + base64.StdEncoding.EncodeToString(byteBuff)
	// 设置 Headers
	req.Header.Set("Authorization", token)

	// 发送请求
	client := dnsla.httpClient
	resp, err := client.Do(req)
	if err != nil {
		return nil, fmt.Errorf("请求 dnsla 记录列表失败: %w", err)
	}
	defer resp.Body.Close()

	// 读取响应
	result, err = io.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("读取 dnsla 记录列表响应失败: %w", err)
	}
	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("dnsla 记录列表请求失败,状态码: %d, 响应: %s", resp.StatusCode, string(result))
	}
	return result, nil
}

View on GitHub (pinned to 5874c2e666)

Solutions

  1. Check the wrapped error (errors.Unwrap / %v of err) to identify timeout vs DNS vs TLS cause
  2. Verify basic connectivity: curl https://api.dnsla.com (or the configured endpoint) from the same host
  3. Check proxy environment variables (HTTP_PROXY/HTTPS_PROXY/NO_PROXY) if behind a corporate network
  4. In minimal containers, install/refresh CA certificates (e.g. apk add ca-certificates)
  5. Add a retry with backoff for transient network errors

Example fix

// before
resp, err := client.Do(req)
if err != nil {
    return nil, fmt.Errorf("请求 dnsla 记录列表失败: %w", err)
}
// after
resp, err := client.Do(req)
if err != nil {
    var netErr net.Error
    if errors.As(err, &netErr) && netErr.Timeout() {
        return nil, fmt.Errorf("请求 dnsla 记录列表超时: %w", err)
    }
    return nil, fmt.Errorf("请求 dnsla 记录列表失败: %w", err)
}
Defensive patterns

Strategy: retry

Validate before calling

// 预检网络连通性
conn, err := net.DialTimeout("tcp", "api.dnsla.com:443", 3*time.Second)
if err != nil {
    return fmt.Errorf("无法连接 dnsla API: %w", err)
}
conn.Close()

Type guard

func isTimeoutErr(err error) bool {
    var netErr net.Error
    return errors.As(err, &netErr) && netErr.Timeout()
}

Try / catch

records, err := getRecordList(...)
if err != nil {
    var netErr net.Error
    if errors.As(err, &netErr) && netErr.Timeout() {
        // 退避重试
        time.Sleep(backoff)
        retry()
    }
    return fmt.Errorf("网络错误,无法请求 dnsla: %w", err)
}

Prevention

When it happens

Trigger: client.Do(req) returns an error: network unreachable, dnsla API host down, DNS lookup failure for the API host, connection timeout, proxy misconfigured in environment (HTTP_PROXY/HTTPS_PROXY), or TLS certificate problems.

Common situations: No internet or firewall blocking outbound HTTPS; corporate proxy requiring auth not configured; dnsla API outage; Go TLS trust store issues in minimal Docker images (missing ca-certificates); IPv6-only environment where the API host has no AAAA record.

Related errors


AI-assisted analysis of jeessy2/ddns-go@5874c2e666 (2026-09-03). Data as JSON: /api/errors/48ef5848055ede47. Report an issue: GitHub.