chenhg5/cc-connect · error

HTTP %d

Error message

HTTP %d

What it means

downloadAttachment got a non-200 status from the CDN/MAX attachment endpoint. Unlike the poll path, the response body (which usually holds the error detail) is discarded and only the status code is reported.

Source

Thrown at platform/max/max.go:1198

// for image/file payloads are already authenticated, so no bot token is
// attached to the request.
func (p *Platform) downloadAttachment(ctx context.Context, url string) ([]byte, string, error) {
	if url == "" {
		return nil, "", fmt.Errorf("empty url")
	}
	dlCtx, cancel := context.WithTimeout(ctx, attachmentDownloadTO)
	defer cancel()
	req, err := http.NewRequestWithContext(dlCtx, http.MethodGet, url, nil)
	if err != nil {
		return nil, "", err
	}
	resp, err := p.client.Do(req)
	if err != nil {
		return nil, "", err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		return nil, "", fmt.Errorf("HTTP %d", resp.StatusCode)
	}
	data, err := io.ReadAll(io.LimitReader(resp.Body, maxAttachmentBytes+1))
	if err != nil {
		return nil, "", err
	}
	if len(data) > maxAttachmentBytes {
		return nil, "", fmt.Errorf("attachment exceeds %d bytes", maxAttachmentBytes)
	}
	return data, resp.Header.Get("Content-Type"), nil
}

// resolveMediaURL asks MAX for the playable/downloadable URL of a video or
// audio attachment. MAX delivers only an opaque token in the message payload
// and exposes /videos/{token} and /audios/{token} for resolution.
func (p *Platform) resolveMediaURL(ctx context.Context, kind, token string) (string, string, error) {
	if token == "" {
		return "", "", fmt.Errorf("empty token")
	}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Download attachments promptly after receiving the message, before the pre-signed link expires
  2. Log respBody on non-200 to see the CDN error detail
  3. Re-fetch a fresh URL via resolveMediaURL and retry once on 403/404
  4. Check whether the attachment was deleted upstream (404) and degrade gracefully

Example fix

// before
if resp.StatusCode != http.StatusOK {
	return nil, "", fmt.Errorf("HTTP %d", resp.StatusCode)
}
// after
if resp.StatusCode != http.StatusOK {
	body, _ := io.ReadAll(io.LimitReader(resp.Body, 512))
	return nil, "", fmt.Errorf("HTTP %d: %s", resp.StatusCode, body)
}
Defensive patterns

Strategy: retry

Try / catch

data, _, err := p.downloadAttachment(ctx, url)
if err != nil && strings.HasPrefix(err.Error(), "HTTP 5") {
	time.Sleep(backoff); retry()
}

Prevention

When it happens

Trigger: The pre-signed URL expired, was revoked, or the CDN returned 403/404/5xx; the URL is reachable but the signature no longer authenticates the download.

Common situations: Downloading an attachment long after the message was received (pre-signed links expire); MAX CDN outage; token revoked by sender deleting the media.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/8a33df39fa3b9113. Report an issue: GitHub.