{"record":{"id":"e718cacafd16952c","repo":"fish2018/pansou","slug":"w-e718ca","errorCode":null,"errorMessage":"解析响应失败: %w","messagePattern":"解析响应失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/pan666/pan666.go","lineNumber":241,"sourceCode":"\t\t}\n\t\t\n\t\t// 状态码检查\n\t\tif resp.StatusCode != http.StatusOK {\n\t\t\tif i == p.retries {\n\t\t\t\treturn nil, false, fmt.Errorf(\"API返回非200状态码: %d\", resp.StatusCode)\n\t\t\t}\n\t\t\ttime.Sleep(500 * time.Millisecond)\n\t\t\tcontinue\n\t\t}\n\t\t\n\t\t// 请求成功，跳出重试循环\n\t\tbreak\n\t}\n\t\n\t// 解析响应\n\tvar apiResp Pan666Response\n\tif err := json.Unmarshal(responseBody, &apiResp); err != nil {\n\t\treturn nil, false, fmt.Errorf(\"解析响应失败: %w\", err)\n\t}\n\t\n\t// 处理结果\n\tresults := make([]model.SearchResult, 0, len(apiResp.Data))\n\tpostMap := make(map[string]Pan666Post)\n\t\n\t// 创建帖子ID到帖子内容的映射\n\tfor _, post := range apiResp.Included {\n\t\tpostMap[post.ID] = post\n\t}\n\t\n\t// 遍历搜索结果\n\tfor _, discussion := range apiResp.Data {\n\t\t// 获取相关帖子\n\t\tpostID := discussion.Relationships.MostRelevantPost.Data.ID\n\t\tpost, ok := postMap[postID]\n\t\tif !ok {\n\t\t\tcontinue","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/pan666/pan666.go#L223-L259","documentation":"pan666 plugin fetchPage wraps json.Unmarshal failures of the search API response body with this Chinese message ('failed to parse response'). It means the upstream pan666 API returned a body that is not valid JSON (or not the expected Pan666Response shape). The plugin treats any non-decodable body as a hard failure and aborts the search.","triggerScenarios":"fetchPage receives an HTTP response whose body cannot be unmarshaled into Pan666Response: HTML error pages, Cloudflare/CAPTCHA interstitials, rate-limit text, empty bodies, or a changed upstream JSON schema.","commonSituations":"Upstream pan666 site is down or behind anti-bot protection; the plugin's User-Agent is blocked; the API endpoint changed its response format after a site update; a proxy/gateway returned a non-JSON error page.","solutions":["Print/log the raw responseBody on failure to see what the upstream actually returned (HTML vs JSON).","Verify the pan666 API endpoint is reachable in a browser or via curl; update the base URL if the site moved.","Add browser-like headers (User-Agent, Referer, Cookie) to the request to bypass anti-bot pages.","If the schema changed, update the Pan666Response struct fields to match the new JSON."],"exampleFix":"// before\nif err := json.Unmarshal(responseBody, &apiResp); err != nil {\n    return nil, false, fmt.Errorf(\"解析响应失败: %w\", err)\n}\n// after\nif err := json.Unmarshal(responseBody, &apiResp); err != nil {\n    return nil, false, fmt.Errorf(\"解析响应失败: %w (body: %.200s)\", err, responseBody)\n}","handlingStrategy":"try-catch","validationCode":"// pre-check before trusting the API\nif len(responseBody) == 0 || responseBody[0] != '{' {\n    return nil, false, fmt.Errorf(\"non-JSON response: %.200s\", responseBody)\n}","typeGuard":"func looksLikeJSON(b []byte) bool {\n    t := bytes.TrimSpace(b)\n    return len(t) > 0 && (t[0] == '{' || t[0] == '[')\n}","tryCatchPattern":"results, partial, err := plugin.FetchPage(keyword)\nif err != nil {\n    var uerr *fmt.Errorf // or errors.As on wrapped json.UnmarshalTypeError\n    log.Printf(\"pan666 parse failed: %v\", err)\n    return fallbackSearch(keyword)\n}","preventionTips":["Log the raw response body on every parse failure to spot HTML/anti-bot pages early.","Send browser-like User-Agent/Referer headers to avoid HTML interstitials.","Monitor the upstream endpoint with a periodic smoke-test request.","Keep Pan666Response fields tolerant (omitempty, pointers) to survive schema drift."],"tags":["json","http","upstream-api","unmarshal"],"backgroundTag":"json-unmarshal-failed","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"}