fish2018/pansou · error

[ ] API错误

Error message

[%s] API错误: %s

What it means

Generic guard in searchImpl rejecting a search response whose JSON body parsed successfully but carried a non-200 business-level Code. The transport layer succeeded (HTTP status was 200 and JSON unmarshalled); the fault is upstream: the miaoso API itself reported an error via its Msg field, e.g. rate limiting, invalid parameters, or server-side failure.

Solutions

  1. 按 Msg 内容区分处理:参数错误修正输入,配额限制降频
  2. 监控该错误以发现 API 协议变更
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at plugin/miaoso/miaoso.go:135 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/f9307372f8f5c8f7. Report an issue: GitHub.

Appendix: source

Thrown at plugin/miaoso/miaoso.go:135

	if resp.StatusCode != 200 {
		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 MiaosouResponse
	if err := json.Unmarshal(body, &apiResp); err != nil {
		return nil, fmt.Errorf("[%s] JSON解析失败: %w", p.Name(), err)
	}
	
	// 检查API响应状态
	if apiResp.Code != 200 {
		return nil, fmt.Errorf("[%s] API错误: %s", p.Name(), apiResp.Msg)
	}
	
	// 转换为标准格式
	results := make([]model.SearchResult, 0, len(apiResp.Data.List))
	for _, item := range apiResp.Data.List {
		result, err := p.convertToSearchResult(item)
		if err != nil {
			continue // 跳过转换失败的项目
		}
		
		// 只添加有链接的结果
		if len(result.Links) > 0 {
			results = append(results, result)
		}
	}
	
	// 关键词过滤
	return results, nil

View on GitHub (pinned to beaa561337)