fish2018/pansou · error
[ ] API错误
Error message
[%s] API错误: %s
What it means
ikantv plugin's doSearch throws this when the decoded apiResponse.Code is not 0 — the API returned an application-level error and its Message field is surfaced verbatim. HTTP transport succeeded; the API rejected the request or reported an internal problem.
Solutions
- Read apiResp.Message in the error — it states the API's own reason.
- Verify the plugin's assumption that Code==0 means success against the current API contract and update if the convention changed.
- Check whether the request needs updated auth/params; retry if the message suggests a transient upstream issue.
- Add handling for known error codes (rate limit, auth) instead of surfacing a generic message.
Example fix
// before
if apiResp.Code != 0 {
return nil, fmt.Errorf("[%s] API错误: %s", p.Name(), apiResp.Message)
}
// after
if apiResp.Code != 0 {
if isRetryable(apiResp.Code) {
return nil, fmt.Errorf("[%s] API错误(可重试): code=%d %s", p.Name(), apiResp.Code, apiResp.Message)
}
return nil, fmt.Errorf("[%s] API错误: code=%d %s", p.Name(), apiResp.Code, apiResp.Message)
} Defensive patterns
Strategy: try-catch
Try / catch
results, err := p.doSearch(ctx, keyword)
if err != nil && strings.Contains(err.Error(), "API错误") {
// application-level rejection: read the embedded apiResp.Message,
// decide retry vs fix-params vs give up
log.Printf("ikantv API rejected request: %v", err)
} Prevention
- Surface apiResp.Message to the user/diagnostics — it explains the rejection
- Confirm the success-code convention (Code==0) still matches the current API
- Do not retry blindly; distinguish quota/auth errors from transient ones
- Keep a per-source error taxonomy so business errors degrade that source only
When it happens
Trigger: apiResp.Code != 0 after successful parse: invalid/missing auth parameter, rate limit at the application layer, unsupported query, or upstream service degraded with an error code in the JSON envelope.
Common situations: The ikantv API changed its status-code convention (success no longer 0); the query triggered a server-side rejection; upstream partial outage reports business errors in the JSON body.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/8e78d511fde8b7fb.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/ikantv/ikantv.go:103
return nil, fmt.Errorf("[%s] 搜索请求失败: %w", p.Name(), err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("[%s] 请求返回状态码: %d", p.Name(), resp.StatusCode)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("[%s] 读取响应失败: %w", p.Name(), err)
}
var apiResp apiResponse
if err := json.Unmarshal(body, &apiResp); err != nil {
return nil, fmt.Errorf("[%s] JSON解析失败: %w", p.Name(), err)
}
if apiResp.Code != 0 {
return nil, fmt.Errorf("[%s] API错误: %s", p.Name(), apiResp.Message)
}
results := convertResults(apiResp.Data)
return plugin.FilterResultsByKeyword(results, keyword), nil
}
func convertResults(items []apiItem) []model.SearchResult {
results := make([]model.SearchResult, 0, len(items))
for _, item := range items {
result, ok := convertResult(item)
if !ok {
continue
}
results = append(results, result)
}
return results
}
View on GitHub (pinned to beaa561337)