fish2018/pansou · error

下载链接请求状态码

Error message

下载链接请求状态码: %d

What it means

getDownloadLinks returns this when the download-links API responds with an HTTP status other than 200. It is a deliberate guard: the plugin only knows how to parse a 200 JSON body, so any other status (403, 404, 5xx) is reported with the numeric code.

Solutions

  1. Log the actual status code and confirm the content id being requested is valid.
  2. Retry later if the code is 5xx or 429 (rate limit); add backoff to doRequestWithRetry.
  3. Inspect the response body for 403 to detect anti-bot/Cloudflare pages and add matching headers/cookies in setRequestHeaders.
  4. Check if the site changed its API endpoint and update the URL in getDownloadLinks.

Example fix

// before
if resp.StatusCode != 200 {
    return nil, fmt.Errorf("下载链接请求状态码: %d", resp.StatusCode)
}
// after
if resp.StatusCode != http.StatusOK {
    body, _ := io.ReadAll(io.LimitReader(resp.Body, 512))
    return nil, fmt.Errorf("下载链接请求状态码: %d, body: %s", resp.StatusCode, body)
}
Defensive patterns

Strategy: validation

Validate before calling

if id == "" {
    return errors.New("content id is required before fetching download links")
}

Try / catch

links, err := p.getDownloadLinks(id)
if err != nil {
    if strings.Contains(err.Error(), "状态码: 4") {
        // treat as client error: invalid id or blocked; don't retry blindly
    }
    return err
}

Prevention

When it happens

Trigger: The GET for download links completes but resp.StatusCode != 200 — e.g. the video/episode id does not exist (404), the site rate-limits or blocks the client (403/429), or the server errors (500/502).

Common situations: Invalid or stale content ID passed by the caller, site added WAF/anti-bot protection returning 403, CDN 5xx during traffic spikes, or the API path changed after a site update.

Related errors


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

Appendix: source

Thrown at plugin/cyg/cyg.go:246

	// 创建请求对象
	req, err := http.NewRequestWithContext(ctx, "GET", downloadURL, nil)
	if err != nil {
		return nil, fmt.Errorf("创建下载链接请求失败: %w", err)
	}

	// 设置请求头
	p.setRequestHeaders(req)

	// 发送请求
	resp, err := p.doRequestWithRetry(req, client)
	if err != nil {
		return nil, fmt.Errorf("下载链接请求失败: %w", err)
	}
	defer resp.Body.Close()

	// 检查状态码
	if resp.StatusCode != 200 {
		return nil, fmt.Errorf("下载链接请求状态码: %d", resp.StatusCode)
	}

	// 解析响应
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("读取下载链接响应失败: %w", err)
	}

	var downloadData []CygDownload
	if err := json.Unmarshal(body, &downloadData); err != nil {
		return nil, fmt.Errorf("下载链接JSON解析失败: %w", err)
	}

	// 转换为model.Link格式
	return p.convertToLinks(downloadData), nil
}

// convertToSearchResult 转换为标准搜索结果格式

View on GitHub (pinned to beaa561337)