fish2018/pansou · error

[ ] 搜索API返回错误

Error message

[%s] 搜索API返回错误: %s

What it means

After successfully parsing the JSON, executeSearch checks searchResp.Code != 0 and reports the upstream API's business-level error message (searchResp.Msg). The JSON was valid, but the XYS search API itself rejected or failed the request and returned a non-zero code.

Solutions

  1. Inspect searchResp.Msg in the error message for the upstream reason and act accordingly.
  2. If Msg indicates rate limiting, back off and slow the request rate.
  3. Refresh cookies/credentials the plugin uses to authenticate with XYS.
  4. Retry later if the upstream reports a transient internal error.
Defensive patterns

Strategy: retry

Try / catch

results, err := search(keyword)
if err != nil {
    if strings.Contains(err.Error(), "搜索API返回错误") {
        // upstream business error; back off and retry
        time.Sleep(backoff)
        return searchWithRetry(keyword, attempts-1)
    }
    return err
}

Prevention

When it happens

Trigger: The XYS search endpoint returned valid JSON with a non-zero Code field — e.g. rate limiting, invalid/expired session cookies, blocked IP, or an invalid query — with the human-readable reason in Msg.

Common situations: Too many rapid searches triggering upstream rate limits; the search keyword triggered a server-side validation error; XYS backend maintenance or API contract changes; expired login cookies the plugin depends on.

Related errors


AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07). Data as JSON: /api/errors/676180297dd7e439. Report an issue: GitHub.

Appendix: source

Thrown at plugin/xys/xys.go:284

	if resp.StatusCode != 200 {
		return nil, fmt.Errorf("[%s] 搜索请求HTTP状态错误: %d", p.Name(), resp.StatusCode)
	}

	// 读取响应体
	respBody, err := io.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("[%s] 读取响应体失败: %w", p.Name(), err)
	}

	// 解析JSON响应
	var searchResp SearchResponse
	if err := json.Unmarshal(respBody, &searchResp); err != nil {
		return nil, fmt.Errorf("[%s] JSON解析失败: %w", p.Name(), err)
	}

	if searchResp.Code != 0 {
		return nil, fmt.Errorf("[%s] 搜索API返回错误: %s", p.Name(), searchResp.Msg)
	}

	if p.debugMode {
		log.Printf("[XYS] 搜索API响应成功,data长度: %d", len(searchResp.Data))
	}

	// 解析HTML内容
	return p.parseSearchResults(searchResp.Data, keyword)
}

// parseSearchResults 解析搜索结果HTML
func (p *XysPlugin) parseSearchResults(htmlData, keyword string) ([]model.SearchResult, error) {
	doc, err := goquery.NewDocumentFromReader(strings.NewReader(htmlData))
	if err != nil {
		return nil, fmt.Errorf("[%s] 解析搜索结果HTML失败: %w", p.Name(), err)
	}

	var results []model.SearchResult

View on GitHub (pinned to beaa561337)