fish2018/pansou · error

[ ] API返回错误状态

Error message

[%s] API返回错误状态: %s

What it means

Application-level rejection from xdyh: JSON decoded fine but the APIResponse.Status field is not "success". The transport and schema were OK; the server rejected the query (bad params, auth, or server-side failure).

Solutions

  1. Map the status string to known failure modes
  2. Retry only for transient statuses; otherwise correct the request
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at plugin/xdyh/xdyh.go:168 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at plugin/xdyh/xdyh.go:168

	if resp.StatusCode != 200 {
		return nil, fmt.Errorf("[%s] 请求返回状态码: %d", pluginName, resp.StatusCode)
	}
	
	// 9. 读取响应体
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("[%s] 读取响应失败: %w", pluginName, err)
	}
	
	// 10. 解析JSON响应
	var apiResp APIResponse
	if err := json.Unmarshal(body, &apiResp); err != nil {
		return nil, fmt.Errorf("[%s] JSON解析失败: %w", pluginName, err)
	}
	
	// 11. 检查API响应状态
	if apiResp.Status != "success" {
		return nil, fmt.Errorf("[%s] API返回错误状态: %s", pluginName, apiResp.Status)
	}
	
	// 12. 转换为标准格式
	results := p.convertToSearchResults(apiResp, keyword)
	
	// 13. 缓存结果
	if len(results) > 0 {
		searchCache.Store(cacheKey, results)
	}
	
	// 14. 关键词过滤
	return plugin.FilterResultsByKeyword(results, keyword), nil
}

// setRequestHeaders 设置HTTP请求头
func (p *XdyhAsyncPlugin) setRequestHeaders(req *http.Request) {
	req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")
	req.Header.Set("Accept", "application/json, text/plain, */*")

View on GitHub (pinned to beaa561337)