{"record":{"id":"ecb701f2c9ec92e5","repo":"fish2018/pansou","slug":"api-returned-error-page-d-s","errorCode":null,"errorMessage":"API returned error (page %d): %s","messagePattern":"API returned error \\(page (.+?)\\): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/hunhepan/hunhepan.go","lineNumber":264,"sourceCode":"\t\t\t\tdebugLog(\"读取响应失败 (page %d): %v\", pageNum, err)\n\t\t\t\terrChan <- fmt.Errorf(\"read response body failed (page %d): %w\", pageNum, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tdebugLog(\"响应内容 (page %d, 前500字符): %s\", pageNum, string(respBody[:min(500, len(respBody))]))\n\n\t\t\t// 解析响应\n\t\t\tvar apiResp HunhepanResponse\n\t\t\tif err := json.Unmarshal(respBody, &apiResp); err != nil {\n\t\t\t\tdebugLog(\"JSON解析失败 (page %d): %v\", pageNum, err)\n\t\t\t\terrChan <- fmt.Errorf(\"decode response failed (page %d): %w\", pageNum, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// 检查响应状态\n\t\t\tif apiResp.Code != 200 {\n\t\t\t\tdebugLog(\"API返回错误 (page %d): code=%d, msg=%s\", pageNum, apiResp.Code, apiResp.Msg)\n\t\t\t\terrChan <- fmt.Errorf(\"API returned error (page %d): %s\", pageNum, apiResp.Msg)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tdebugLog(\"成功获取第 %d 页数据，共 %d 条结果\", pageNum, len(apiResp.Data.List))\n\n\t\t\t// 将结果发送到通道\n\t\t\tresultChan <- apiResp.Data.List\n\t\t}(page)\n\t}\n\n\t// 启动一个goroutine等待所有页面请求完成并关闭通道\n\tgo func() {\n\t\twg.Wait()\n\t\tclose(resultChan)\n\t\tclose(errChan)\n\t}()\n\n\t// 收集结果","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/hunhepan/hunhepan.go#L246-L282","documentation":"Hunhepan plugin throws this when the decoded response has Code != 200, i.e. the API answered successfully at the HTTP level but reported an application-level error. The message string from the API (apiResp.Msg) is included verbatim.","triggerScenarios":"apiResp.Code != 200 after successful request and JSON decode: API-side quota/rate limit, invalid or missing API token, banned key, or an invalid request parameter (e.g. bad query or page number).","commonSituations":"API key expired or exceeded daily quota; the upstream service changed its status-code convention; search keyword triggered a server-side rejection.","solutions":["Read apiResp.Msg in the error text — it states the API's own reason (quota, auth, etc.).","Verify the hunhepan API token/key configured for the plugin is valid and not rate-limited.","Check the request parameters (keyword encoding, pageNum bounds) against the current API docs.","Compare the plugin's expected success code (200) against any recent API contract changes."],"exampleFix":"// before\nif apiResp.Code != 200 {\n\terrChan <- fmt.Errorf(\"API returned error (page %d): %s\", pageNum, apiResp.Msg)\n\treturn\n}\n// after\nif apiResp.Code != 200 {\n\tif apiResp.Code == 401 || apiResp.Code == 429 {\n\t\terrChan <- fmt.Errorf(\"API returned error (page %d): code=%d (auth/rate-limit) %s\", pageNum, apiResp.Code, apiResp.Msg)\n\t} else {\n\t\terrChan <- fmt.Errorf(\"API returned error (page %d): code=%d %s\", pageNum, apiResp.Code, apiResp.Msg)\n\t}\n\treturn\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"results, err := plugin.Search(ctx, keyword)\nif err != nil && strings.Contains(err.Error(), \"API returned error\") {\n\t// application-level rejection: surface apiResp.Msg to the user,\n\t// check token/quota before retrying\n\tlog.Printf(\"hunhepan rejected the request: %v\", err)\n}","preventionTips":["Keep the hunhepan API token valid and within quota","Read the embedded apiResp.Msg — it names the exact API-side reason","Don't blindly retry application-level errors; fix auth/params first","Track upstream API contract changes for the success code (200)"],"tags":["api","go","http","upstream"],"backgroundTag":"api-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"}