{"record":{"id":"2386a0a702db3e91","repo":"fish2018/pansou","slug":"s-http-d-2386a0","errorCode":null,"errorMessage":"[%s] 搜索请求HTTP状态错误: %d","messagePattern":"\\[(.+?)\\] 搜索请求HTTP状态错误: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/xys/xys.go","lineNumber":268,"sourceCode":"\n\t// 设置完整的请求头\n\treq.Header.Set(\"User-Agent\", UserAgent)\n\treq.Header.Set(\"Accept\", \"application/json, text/plain, */*\")\n\treq.Header.Set(\"Accept-Language\", \"zh-CN,zh;q=0.9,en;q=0.8\")\n\treq.Header.Set(\"Connection\", \"keep-alive\")\n\treq.Header.Set(\"Content-Type\", \"application/x-www-form-urlencoded\")\n\treq.Header.Set(\"Referer\", BaseURL+\"/\")\n\treq.Header.Set(\"Origin\", BaseURL)\n\treq.Header.Set(\"X-Requested-With\", \"XMLHttpRequest\")\n\n\tresp, err := p.doRequestWithRetry(req, client)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 搜索请求失败: %w\", p.Name(), err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != 200 {\n\t\treturn nil, fmt.Errorf(\"[%s] 搜索请求HTTP状态错误: %d\", p.Name(), resp.StatusCode)\n\t}\n\n\t// 读取响应体\n\trespBody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 读取响应体失败: %w\", p.Name(), err)\n\t}\n\n\t// 解析JSON响应\n\tvar searchResp SearchResponse\n\tif err := json.Unmarshal(respBody, &searchResp); err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] JSON解析失败: %w\", p.Name(), err)\n\t}\n\n\tif searchResp.Code != 0 {\n\t\treturn nil, fmt.Errorf(\"[%s] 搜索API返回错误: %s\", p.Name(), searchResp.Msg)\n\t}\n","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/xys/xys.go#L250-L286","documentation":"executeSearch rejects the search response when the HTTP status is not 200. The plugin expects a JSON body and only accepts an exact 200; anything else (403 anti-bot, 4xx validation, 5xx outage) aborts parsing and reports the status code.","triggerScenarios":"doRequestWithRetry succeeded but resp.StatusCode != 200 on the search POST — e.g. 403 from WAF, 400 from an expired/invalid DToken2, 500 from the search backend.","commonSituations":"Token expired between fetch and search yielding 401/403; anti-bot challenge on the API endpoint; upstream search service outage (5xx); request rate limited (429).","solutions":["Log the status code and response body to identify the server's complaint","Re-fetch the DToken (clear the token cache) if the status is 401/403, since an expired token commonly causes it","Check rate limits and reduce request frequency or rotate IP/proxy on 429/403","Retry later on 5xx; verify the search endpoint still exists if you get persistent 404s"],"exampleFix":"// before\nif resp.StatusCode != 200 {\n    return nil, fmt.Errorf(\"[%s] 搜索请求HTTP状态错误: %d\", p.Name(), resp.StatusCode)\n}\n// after\nif resp.StatusCode == 401 || resp.StatusCode == 403 {\n    p.tokenCache.Delete(cacheKey) // force token refresh on next call\n    return nil, fmt.Errorf(\"[%s] 搜索请求HTTP状态错误: %d (token可能已失效, 将重新获取)\", p.Name(), resp.StatusCode)\n}\nif resp.StatusCode != 200 {\n    return nil, fmt.Errorf(\"[%s] 搜索请求HTTP状态错误: %d\", p.Name(), resp.StatusCode)\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"var se *StatusError\nif errors.As(err, &se) {\n    switch {\n    case se.Code == 401 || se.Code == 403:\n        invalidateToken(); return retryOnce()\n    case se.Code == 429:\n        return retryAfter(se.RetryAfter)\n    case se.Code >= 500:\n        return retryWithBackoff()\n    }\n    return nil, err\n}","preventionTips":["Automatically refresh the DToken on 401/403 responses","Log status + body snippet for every non-200 to speed triage","Respect 429 Retry-After headers and add client-side rate limiting","Alert on 5xx rates to detect upstream outages early"],"tags":["http","http-status","api","upstream"],"backgroundTag":"http-non-200-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"}