fish2018/pansou · error
[ ] API返回错误: success= , code=
Error message
[%s] API返回错误: success=%v, code=%s
What it means
The search API responded with parseable JSON, but its business status is a failure: success is false, or the code field is present and not "200". This is the API's own error envelope — transport and parsing succeeded, the backend rejected or failed the query.
Solutions
- Include the API's msg/message field in the error to learn why it failed
- Refresh the anti-bot session (ensureSession) and retry once when success=false
- Log apiResp.Code plus any message field to distinguish auth/session failure from backend error
- If code is a rate-limit code, back off and retry with jitter
- Treat persistent success=false as a site/API change and re-check the upstream contract
Example fix
// before
if !apiResp.Success || (apiResp.Code != "" && apiResp.Code != "200") {
return nil, fmt.Errorf("[%s] API返回错误: success=%v, code=%s", p.Name(), apiResp.Success, apiResp.Code)
}
// after
if !apiResp.Success || (apiResp.Code != "" && apiResp.Code != "200") {
return nil, fmt.Errorf("[%s] API返回错误: success=%v, code=%s, msg=%s", p.Name(), apiResp.Success, apiResp.Code, apiResp.Msg)
} Defensive patterns
Strategy: fallback
Try / catch
results, err := plugin.Search(keyword, ext)
if err != nil && strings.Contains(err.Error(), "API返回错误") {
log.Info("nsgame business error, falling back", "err", err)
return fallbackSources.Search(keyword, ext)
} Prevention
- Treat success=false as retryable-once after session refresh, then permanent
- Surface the API's message field so failures are diagnosable
- Back off on rate-limit-style codes instead of hammering
- Track upstream API contract changes with periodic smoke tests
When it happens
Trigger: API returns {"success":false,...} for an invalid/expired session, a blocked query keyword, server-side rate limiting expressed in the envelope, or an internal backend error with a non-200 code string.
Common situations: Anti-bot session cookie expired mid-run causing the API to report failure; query keyword triggered server-side filtering; upstream service degraded and returns code "500" in the JSON body with HTTP 200.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/88289f9f2fb1d43a.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/nsgame/nsgame.go:184
if resp.StatusCode != 200 {
return nil, fmt.Errorf("[%s] 请求返回状态码: %d", p.Name(), resp.StatusCode)
}
// 6. 读取响应体
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("[%s] 读取响应失败: %w", p.Name(), err)
}
// 7. 解析JSON响应
var apiResp NSGameResponse
if err := json.Unmarshal(body, &apiResp); err != nil {
return nil, fmt.Errorf("[%s] JSON解析失败: %w", p.Name(), err)
}
// 8. 检查响应状态
if !apiResp.Success || (apiResp.Code != "" && apiResp.Code != "200") {
return nil, fmt.Errorf("[%s] API返回错误: success=%v, code=%s", p.Name(), apiResp.Success, apiResp.Code)
}
// 9. 转换为标准格式
items := apiResp.Data.PageData.Data
var results []model.SearchResult
var wg sync.WaitGroup
var mu sync.Mutex
sem := make(chan struct{}, 8)
for _, item := range items {
item := item
if item.ID == 0 {
continue
}
wg.Add(1)
sem <- struct{}{}
go func() {
defer wg.Done()
defer func() { <-sem }()View on GitHub (pinned to beaa561337)