fish2018/pansou · error

[ ] 网盘第 页API错误

Error message

[%s] %s网盘第%d页API错误: %s

What it means

This error is thrown when the haisou search API returned parseable JSON but the business status field apiResp.Code is not 0, meaning the upstream API rejected the search request for that pan type and page. The API's error message (apiResp.Msg) is embedded so the developer can see the upstream reason (e.g. invalid key, quota exceeded, bad parameters).

Solutions

  1. Inspect the embedded apiResp.Msg for the upstream reason and address it accordingly
  2. Verify API credentials/parameters sent in the search request
  3. Retry with a different pageNo or reduced query frequency to rule out rate limiting
  4. Check upstream API documentation/changelog for new status codes
  5. Add handling for well-known Code values (e.g. auto-refresh token, back off on quota).

Example fix

// before
if apiResp.Code != 0 {
	return nil, fmt.Errorf("[%s] %s网盘第%d页API错误: %s", p.Name(), panType, pageNo, apiResp.Msg)
}
// after
if apiResp.Code != 0 {
	if isRetryableCode(apiResp.Code) {
		time.Sleep(retryBackoff(pageNo))
		return p.fetchSearchPage(panType, keyword, pageNo)
	}
	return nil, fmt.Errorf("[%s] %s网盘第%d页API错误: code=%d msg=%s", p.Name(), panType, pageNo, apiResp.Code, apiResp.Msg)
}
Defensive patterns

Strategy: fallback

Validate before calling

// no pre-call validation possible; Code is only known after the response
// defend by handling non-zero codes in a switch on known values

Type guard

func isUpstreamOK(resp SearchAPIResponse) bool { return resp.Code == 0 }

Try / catch

var apiResp SearchAPIResponse
if err := json.Unmarshal(body, &apiResp); err != nil { return err }
if apiResp.Code != 0 {
	return fmt.Errorf("upstream rejected search: code=%d msg=%s", apiResp.Code, apiResp.Msg)
}

Prevention

When it happens

Trigger: fetchSearchPage receives a JSON response whose Code field is non-zero, after successful unmarshalling of the search API response.

Common situations: Upstream API key/token expired; search keyword blocked or too short; page number beyond available results; upstream rate limiting reported via Code; API changed its status-code semantics.

Related errors


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

Appendix: source

Thrown at plugin/haisou/haisou.go:364

	if resp.StatusCode != 200 {
		return nil, fmt.Errorf("[%s] %s网盘第%d页返回状态码: %d", p.Name(), panType, pageNo, resp.StatusCode)
	}

	// 读取响应体
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("[%s] %s网盘第%d页读取响应失败: %w", p.Name(), panType, pageNo, err)
	}

	// 解析响应
	var apiResp SearchAPIResponse
	if err := json.Unmarshal(body, &apiResp); err != nil {
		return nil, fmt.Errorf("[%s] %s网盘第%d页JSON解析失败: %w", p.Name(), panType, pageNo, err)
	}

	// 检查API响应状态
	if apiResp.Code != 0 {
		return nil, fmt.Errorf("[%s] %s网盘第%d页API错误: %s", p.Name(), panType, pageNo, apiResp.Msg)
	}

	if DebugLog {
		fmt.Printf("[%s] %s网盘第%d页获取到 %d 个搜索结果\n", p.Name(), panType, pageNo, len(apiResp.Data.List))
	}

	return apiResp.Data.List, nil
}

// fetchShareLink 通过hsid获取具体的分享链接
func (p *HaisouPlugin) fetchShareLink(client *http.Client, hsid string, platform string) (string, string, error) {
	// 构建获取链接的URL
	fetchURL := fmt.Sprintf("https://haisou.cc/api/pan/share/%s/fetch", hsid)

	if DebugLog {
		fmt.Printf("[%s] 获取链接 hsid=%s platform=%s: %s\n", p.Name(), hsid, platform, fetchURL)
	}

View on GitHub (pinned to beaa561337)