{"record":{"id":"193a46aa22366077","repo":"fish2018/pansou","slug":"http-d-193a46","errorCode":null,"errorMessage":"HTTP 状态码 %d","messagePattern":"HTTP 状态码 (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"plugin/jupansou/jupansou.go","lineNumber":334,"sourceCode":"\t\t\treturn value\n\t\t}\n\t}\n\treturn \"\"\n}\n\nfunc doJuPansouRequestWithRetry(req *http.Request, client *http.Client) (*http.Response, error) {\n\tvar lastErr error\n\tfor attempt := 0; attempt < jupansouMaxRetries; attempt++ {\n\t\tresp, err := client.Do(req.Clone(req.Context()))\n\t\tif err == nil && resp.StatusCode == http.StatusOK {\n\t\t\treturn resp, nil\n\t\t}\n\t\tif resp != nil {\n\t\t\tresp.Body.Close()\n\t\t}\n\t\tlastErr = err\n\t\tif lastErr == nil {\n\t\t\tlastErr = fmt.Errorf(\"HTTP 状态码 %d\", resp.StatusCode)\n\t\t}\n\t\tif attempt < jupansouMaxRetries-1 {\n\t\t\ttime.Sleep(200 * time.Millisecond * time.Duration(1<<attempt))\n\t\t}\n\t}\n\treturn nil, fmt.Errorf(\"重试 %d 次后失败: %w\", jupansouMaxRetries, lastErr)\n}\n","sourceCodeStart":316,"sourceCodeEnd":342,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/jupansou/jupansou.go#L316-L342","documentation":"Inside doJuPansouRequestWithRetry's retry loop, when an attempt ends with a nil error but a non-2xx status, lastErr is set to this synthetic \"HTTP 状态码 %d\" error so the final retry-exhausted error carries the status. It records that the server answered with a rejected status code on the last attempt.","triggerScenarios":"An attempt in the retry loop receives a response whose status code triggered the retry path (e.g. 429/503), so lastErr is set to `HTTP 状态码 %d` before backoff and the next attempt.","commonSituations":"Rate limiting (429) from polling too fast; temporary upstream overload (503); WAF responses (403) on some attempts that alternate with failures.","solutions":["Read the recorded status code in the final wrapped error to know why retries failed.","Reduce request rate if the code is 429; add jitter to backoff.","Improve headers/cookies if the code is 403 (anti-bot).","Check upstream health for persistent 5xx.","Increase jupansouMaxRetries for bursty transient errors."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"_, err := p.search(client, keyword)\nif err != nil && strings.Contains(err.Error(), \"HTTP 状态码 429\") {\n    time.Sleep(time.Minute) // honor rate limit before next call\n}","preventionTips":["Honor Retry-After headers when present instead of fixed backoff.","Add jitter to retry delays to avoid synchronized hammering.","Keep per-source request budgets so one plugin cannot exhaust limits."],"tags":["http","status-code","retry","rate-limit"],"backgroundTag":"http-error-response","analyzedSha":"beaa56133755a548ebc51b090b3816e2ae044aa6","analyzedAt":"2026-09-07T00:31:18.025Z","contentChangedAt":"2026-09-07T00:31:18.025Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}