{"record":{"id":"77ea49d7b462bb1b","repo":"jeessy2/ddns-go","slug":"api-d-s-77ea49","errorCode":null,"errorMessage":"API请求失败，状态码: %d, 响应: %s","messagePattern":"API请求失败，状态码: (.+?), 响应: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dns/tnethk.go","lineNumber":284,"sourceCode":"\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":266,"sourceCodeEnd":289,"githubUrl":"https://github.com/jeessy2/ddns-go/blob/5874c2e6667c69357ab95079421131104bd3fcae/dns/tnethk.go#L266-L289","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Go: preflight credential check against the API with curl-equivalent\n// curl -o /dev/null -w \"%{http_code}\" \"https://www.tnet.hk/api/...?Signature=...\"\n// Also validate clock skew:\nlocal := time.Now().Unix()\n// if local drifts from NTP by minutes, HMAC signatures will be rejected (4xx)","typeGuard":null,"tryCatchPattern":"// Go\nrecords, err := provider.GetRecordList(domain)\nif err != nil {\n    var status int\n    if n, _ := fmt.Sscanf(err.Error(), \"API请求失败，状态码: %d\", &status); n == 1 {\n        switch {\n        case status == 401 || status == 403:\n            return fmt.Errorf(\"Tnet credentials rejected (HTTP %d): check API ID/SecretKey\", status)\n        case status == 429 || status >= 500:\n            return retryLater(err)\n        }\n    }\n    return err\n}","preventionTips":["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"],"tags":["http","api-error","dns-provider","status-code"],"backgroundTag":"http-non-200-response","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"}