jeessy2/ddns-go · error
API请求失败,状态码: %d, 响应: %s
Error message
API请求失败,状态码: %d, 响应: %s
What it means
Thrown by Tnet.hk's request() helper (dns/tnethk.go:284) when the API responds with any HTTP status other than 200. The message embeds the numeric status code and the raw response body, which usually contains the API's JSON error explanation (e.g. auth/signature failure or invalid parameters). It is the generic non-2xx handler for create, modify and getRecordList calls.
Source
Thrown at dns/tnethk.go:284
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
- Read the response body embedded in the error — it states the API's actual reason
- Verify API ID/SecretKey credentials in the provider config are current
- Check system clock (signature skew) — run ntp/chrony sync if signatures are rejected
- Validate the record/domain parameters passed to create/modify/getRecordList
- Retry later if status is 5xx or 429 (Tnet-side issue or rate limit)
Defensive patterns
Strategy: try-catch
Validate before calling
// Go: preflight credential check against the API with curl-equivalent
// curl -o /dev/null -w "%{http_code}" "https://www.tnet.hk/api/...?Signature=..."
// Also validate clock skew:
local := time.Now().Unix()
// if local drifts from NTP by minutes, HMAC signatures will be rejected (4xx) Try / catch
// Go
records, err := provider.GetRecordList(domain)
if err != nil {
var status int
if n, _ := fmt.Sscanf(err.Error(), "API请求失败,状态码: %d", &status); n == 1 {
switch {
case status == 401 || status == 403:
return fmt.Errorf("Tnet credentials rejected (HTTP %d): check API ID/SecretKey", status)
case status == 429 || status >= 500:
return retryLater(err)
}
}
return err
} Prevention
- Keep Tnet.hk API credentials in config up to date; test after key rotation
- Keep system clock NTP-synced — signature auth fails on skew
- Log the response body embedded in the error to get the API's real reason
- Validate domain/record parameters before calling create/modify
When it happens
Trigger: Expired or wrong API credentials producing 401/403; invalid record parameters producing 400; signature mismatch (bad SecretKey/system clock skew) producing 4xx; Tnet server-side errors returning 5xx; rate limiting returning 429.
Common situations: Rotated Tnet.hk API keys not updated in config; system clock drift breaking the HMAC signature; DNS record ID that does not exist; domain not added to the Tnet account; Tnet API outage or maintenance.
Related errors
- dnsla 记录列表请求失败,状态码: %d, 响应: %s
- API请求失败,状态码: %d, 响应: %s
- Vercel API returned status code %d
- dnsla 请求失败,状态码: %d, 响应: %s
- 读取响应失败: %v
AI-assisted analysis of jeessy2/ddns-go@5874c2e666 (2026-09-03).
Data as JSON: /api/errors/77ea49d7b462bb1b.
Report an issue: GitHub.