jeessy2/ddns-go · error

读取响应失败: %v

Error message

读取响应失败: %v

What it means

Thrown by Eranet.request when io.ReadAll fails to read the response body from the eranet.com API after a successful HTTP round-trip. This is rare and usually indicates the connection dropped mid-response, the body stream errored, or something interfered with resp.Body.

Source

Thrown at dns/eranet.go:279

	if err != nil {
		return nil, fmt.Errorf("创建请求失败: %v", err)
	}

	// 设置请求头
	req.Header.Set("Accept", "application/json")

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

	// 读取响应
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("读取响应失败: %v", err)
	}

	// 检查HTTP状态码
	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("API请求失败,状态码: %d, 响应: %s", resp.StatusCode, string(body))
	}

	return body, nil
}

View on GitHub (pinned to 5874c2e666)

Solutions

  1. Retry the request — the failure is usually transient
  2. Increase the http.Client timeout if body reads are being cut off
  3. Check whether a proxy or middlebox truncates responses
  4. Verify the eranet API endpoint is healthy (compare with curl output)

Example fix

// before
body, err := io.ReadAll(resp.Body)
if err != nil {
    return nil, fmt.Errorf("读取响应失败: %v", err)
}
// after
body, err := io.ReadAll(resp.Body)
if err != nil {
    return nil, fmt.Errorf("读取响应失败: %w", err) // caller should retry
}
Defensive patterns

Strategy: retry

Type guard

var netErr net.Error
if errors.As(err, &netErr) && netErr.Timeout() {
    // body read hit a timeout — safe to retry
}

Try / catch

body, err := eranetClient.ModifyRecord(params)
if err != nil {
    if strings.Contains(err.Error(), "读取响应失败") {
        return retryWithBackoff(3, func() error {
            _, err = eranetClient.ModifyRecord(params)
            return err
        })
    }
    return err
}

Prevention

When it happens

Trigger: io.ReadAll(resp.Body) returns an error: server closed the connection before sending the full body, chunked transfer-encoding error, or the response context/timer expired while reading.

Common situations: Unstable network dropping large responses mid-transfer; eranet API server prematurely closing keep-alive connections; client timeouts that cut off body reads.

Related errors


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