jeessy2/ddns-go · error

%s

Error message

%s

What it means

GetHTTPResponse reads an HTTP response body and returns an error when the HTTP status code is 300 or above (redirect-or-worse treated as failure). The error message embeds the full response body and the status code, so it surfaces the remote server's own error payload. This library deliberately treats any non-2xx/non-early-2xx status as an exceptional condition for API calls (e.g. DNS provider webhooks/record updates).

Source

Thrown at util/http_util.go:41

}

// GetHTTPResponseOrg 处理HTTP结果,返回byte
func GetHTTPResponseOrg(resp *http.Response, err error) ([]byte, error) {
	if err != nil {
		return nil, err
	}

	defer resp.Body.Close()
	lr := io.LimitReader(resp.Body, 1024000)
	body, err := io.ReadAll(lr)

	if err != nil {
		return nil, err
	}

	// 300及以上状态码都算异常
	if resp.StatusCode >= 300 {
		err = fmt.Errorf("%s", LogStr("返回内容: %s ,返回状态码: %d", string(body), resp.StatusCode))
	}

	return body, err
}

View on GitHub (pinned to 5874c2e666)

Solutions

  1. Inspect the response body embedded in the error message — it contains the provider's actual error description and status code
  2. Verify API credentials/tokens configured for the DNS/webhook call
  3. Check whether the API endpoint URL is still valid and whether redirects are expected (consider following redirects before calling)
  4. Retry with backoff if the status is 429 or 5xx; otherwise fix the request payload/credentials
Defensive patterns

Strategy: try-catch

Validate before calling

// Check reachability/credentials before calling
resp, err := http.Head(apiURL)
if err == nil && resp.StatusCode >= 300 {
    return fmt.Errorf("API endpoint unhealthy: %d", resp.StatusCode)
}

Try / catch

body, err := GetHTTPResponseOrg(...)
if err != nil {
    var httpErr string = err.Error() // contains body + status code
    if strings.Contains(httpErr, "返回状态码: 401") || strings.Contains(httpErr, "返回状态码: 403") {
        // fix credentials and retry once
    } else if strings.Contains(httpErr, "返回状态码: 429") || strings.Contains(httpErr, "返回状态码: 5") {
        // retry with backoff
    }
    return err
}

Prevention

When it happens

Trigger: Any HTTP request made via GetHTTPResponseOrg (used by ExecWebhook, addUpdateDomainRecords, sendReq, GetHTTPResponse) that receives a status code >= 300, e.g. 301/302 redirects, 401 invalid API key/token, 403 forbidden, 404 wrong endpoint, 429 rate limit, or 5xx server errors.

Common situations: Expired or wrong DNS provider API credentials causing 401/403; API endpoint changed producing 404; provider rate limiting (429); server-side 5xx outage; proxy/gateway returning HTML error pages; misconfigured webhook URL.

Related errors


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