{"record":{"id":"a58f6d09dbf822a6","repo":"jeessy2/ddns-go","slug":"s-a58f6d","errorCode":null,"errorMessage":"%s","messagePattern":"%s","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/http_util.go","lineNumber":41,"sourceCode":"}\n\n// GetHTTPResponseOrg 处理HTTP结果，返回byte\nfunc GetHTTPResponseOrg(resp *http.Response, err error) ([]byte, error) {\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tdefer resp.Body.Close()\n\tlr := io.LimitReader(resp.Body, 1024000)\n\tbody, err := io.ReadAll(lr)\n\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// 300及以上状态码都算异常\n\tif resp.StatusCode >= 300 {\n\t\terr = fmt.Errorf(\"%s\", LogStr(\"返回内容: %s ,返回状态码: %d\", string(body), resp.StatusCode))\n\t}\n\n\treturn body, err\n}\n","sourceCodeStart":23,"sourceCodeEnd":46,"githubUrl":"https://github.com/jeessy2/ddns-go/blob/5874c2e6667c69357ab95079421131104bd3fcae/util/http_util.go#L23-L46","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the response body embedded in the error message — it contains the provider's actual error description and status code","Verify API credentials/tokens configured for the DNS/webhook call","Check whether the API endpoint URL is still valid and whether redirects are expected (consider following redirects before calling)","Retry with backoff if the status is 429 or 5xx; otherwise fix the request payload/credentials"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Check reachability/credentials before calling\nresp, err := http.Head(apiURL)\nif err == nil && resp.StatusCode >= 300 {\n    return fmt.Errorf(\"API endpoint unhealthy: %d\", resp.StatusCode)\n}","typeGuard":null,"tryCatchPattern":"body, err := GetHTTPResponseOrg(...)\nif err != nil {\n    var httpErr string = err.Error() // contains body + status code\n    if strings.Contains(httpErr, \"返回状态码: 401\") || strings.Contains(httpErr, \"返回状态码: 403\") {\n        // fix credentials and retry once\n    } else if strings.Contains(httpErr, \"返回状态码: 429\") || strings.Contains(httpErr, \"返回状态码: 5\") {\n        // retry with backoff\n    }\n    return err\n}","preventionTips":["Validate API tokens/keys before running update jobs","Monitor provider status pages for 5xx outages","Log the embedded response body for every failed call","Handle 429 with exponential backoff instead of tight retries"],"tags":["http","network","api"],"backgroundTag":"http-4xx-5xx-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"}