chenhg5/cc-connect · error
resource request: %w
Error message
resource request: %w
What it means
The HTTP request issued by resourceSingleGet failed at the transport level: p.resourceDownloadHTTP.Do returned an error (DNS failure, connection refused/reset, TLS error, context cancellation/timeout). The library wraps it as "resource request" so callers know the failure happened while contacting the Feishu resource endpoint.
Source
Thrown at platform/feishu/resource_download.go:263
func (p *Platform) resourceURL(messageID, fileKey, resType string) string {
return fmt.Sprintf("%s/open-apis/im/v1/messages/%s/resources/%s?type=%s",
strings.TrimRight(p.domain, "/"), messageID, fileKey, resType)
}
// resourceSingleGet downloads the entire resource with one plain GET. Used
// for small files and as a fallback when the size probe fails. We honour
// resourceMaxBytes via Content-Length + body cap so a misbehaving server
// can't blow up memory.
func (p *Platform) resourceSingleGet(ctx context.Context, token, messageID, fileKey, resType string) ([]byte, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, p.resourceURL(messageID, fileKey, resType), nil)
if err != nil {
return nil, fmt.Errorf("build request: %w", err)
}
req.Header.Set("Authorization", "Bearer "+token)
resp, err := p.resourceDownloadHTTP.Do(req)
if err != nil {
return nil, fmt.Errorf("resource request: %w", err)
}
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
body, _ := io.ReadAll(io.LimitReader(resp.Body, 4*1024))
return nil, fmt.Errorf("resource API status=%d body=%q", resp.StatusCode, strings.TrimSpace(string(body)))
}
if cl := resp.ContentLength; cl > p.resourceMaxBytes {
return nil, fmt.Errorf("resource too large: Content-Length=%d exceeds cap %d", cl, p.resourceMaxBytes)
}
// LimitReader caps the body too in case the server lies about
// Content-Length; we read up to cap+1 bytes to detect the lie.
data, err := io.ReadAll(io.LimitReader(resp.Body, p.resourceMaxBytes+1))
if err != nil {
return nil, fmt.Errorf("read resource: %w", err)
}View on GitHub (pinned to 4000b2338a)
Solutions
- Inspect the wrapped cause (%w): net.Error timeouts suggest increasing the HTTP client timeout or ctx deadline; connection errors suggest network/proxy problems
- Verify egress connectivity to the Feishu API host (curl the resource URL host from the deployment machine)
- Configure proxy environment variables / a custom http.Transport on resourceDownloadHTTP if behind a proxy
- If the cause is context.DeadlineExceeded, increase the timeout passed via ctx for large-file downloads
- Retry — resourceDownloadStream callers may recover from transient network errors
Example fix
// before: default client, no timeout tuning
resp, err := p.resourceDownloadHTTP.Do(req)
// after: dedicated transport with sane timeouts
p.resourceDownloadHTTP = &http.Client{
Timeout: 5 * time.Minute,
Transport: &http.Transport{Proxy: http.ProxyFromEnvironment},
} Defensive patterns
Strategy: retry
Validate before calling
// pre-flight connectivity check
resp, err := http.Get("https://open.feishu.cn/open-apis")
if err != nil { log.Warn("feishu unreachable", "err", err) } else { resp.Body.Close() } Try / catch
data, err := p.resourceSingleGet(ctx, token, msgID, fileKey, resType)
if err != nil {
if strings.Contains(err.Error(), "resource request:") {
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
// increase timeout and retry once
}
return backoffRetry(ctx, 3, download)
}
return err
} Prevention
- Set explicit timeouts on the resourceDownloadHTTP client and context
- Configure proxy settings (HTTP_PROXY/HTTPS_PROXY) in restricted environments
- Monitor egress connectivity/DNS health in the deployment environment
When it happens
Trigger: Calling resourceDownloadStream for a small file (or when the size probe fails) triggers resourceSingleGet; the GET to the resource URL fails before a response is received — no network, DNS failure, proxy error, TLS problem, or the ctx deadline expires mid-request.
Common situations: No internet access or DNS resolution failing in the deployment environment; corporate proxy not configured for the resourceDownloadHTTP client; context timeout too short for large files on slow links; firewall blocking egress to open.feishu.cn.
Related errors
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/56979f4ccfeef5c2.
Report an issue: GitHub.