fish2018/pansou · error
API returned error (page )
Error message
API returned error (page %d): %s
What it means
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.
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.
Example fix
// before
if apiResp.Code != 200 {
errChan <- fmt.Errorf("API returned error (page %d): %s", pageNum, apiResp.Msg)
return
}
// after
if apiResp.Code != 200 {
if apiResp.Code == 401 || apiResp.Code == 429 {
errChan <- fmt.Errorf("API returned error (page %d): code=%d (auth/rate-limit) %s", pageNum, apiResp.Code, apiResp.Msg)
} else {
errChan <- fmt.Errorf("API returned error (page %d): code=%d %s", pageNum, apiResp.Code, apiResp.Msg)
}
return
} Defensive patterns
Strategy: try-catch
Try / catch
results, err := plugin.Search(ctx, keyword)
if err != nil && strings.Contains(err.Error(), "API returned error") {
// application-level rejection: surface apiResp.Msg to the user,
// check token/quota before retrying
log.Printf("hunhepan rejected the request: %v", err)
} Prevention
- 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)
When it happens
Trigger: 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).
Common situations: API key expired or exceeded daily quota; the upstream service changed its status-code convention; search keyword triggered a server-side rejection.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/ecb701f2c9ec92e5.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/hunhepan/hunhepan.go:264
debugLog("读取响应失败 (page %d): %v", pageNum, err)
errChan <- fmt.Errorf("read response body failed (page %d): %w", pageNum, err)
return
}
debugLog("响应内容 (page %d, 前500字符): %s", pageNum, string(respBody[:min(500, len(respBody))]))
// 解析响应
var apiResp HunhepanResponse
if err := json.Unmarshal(respBody, &apiResp); err != nil {
debugLog("JSON解析失败 (page %d): %v", pageNum, err)
errChan <- fmt.Errorf("decode response failed (page %d): %w", pageNum, err)
return
}
// 检查响应状态
if apiResp.Code != 200 {
debugLog("API返回错误 (page %d): code=%d, msg=%s", pageNum, apiResp.Code, apiResp.Msg)
errChan <- fmt.Errorf("API returned error (page %d): %s", pageNum, apiResp.Msg)
return
}
debugLog("成功获取第 %d 页数据,共 %d 条结果", pageNum, len(apiResp.Data.List))
// 将结果发送到通道
resultChan <- apiResp.Data.List
}(page)
}
// 启动一个goroutine等待所有页面请求完成并关闭通道
go func() {
wg.Wait()
close(resultChan)
close(errChan)
}()
// 收集结果View on GitHub (pinned to beaa561337)