chenhg5/cc-connect · error

range request status=%d body=%q

Error message

range request status=%d body=%q

What it means

Final failure path of resourceRangeChunk: a ranged request returned a status that is neither a usable 206 nor a full-body 200 with the exact requested length. The error carries the status code and a 4 KiB body snippet so the caller can see why the server rejected the range (auth, permission, not found, bad request, etc.).

Source

Thrown at platform/feishu/resource_download.go:375

		// Non-206 response: capture a snippet for diagnostics, then either
		// retry (transient 5xx) or fail fast.
		body, _ := io.ReadAll(io.LimitReader(resp.Body, 4*1024))
		_ = resp.Body.Close()

		if resp.StatusCode >= 500 && resp.StatusCode < 600 && attempt < maxTransientRetries {
			lastErr = fmt.Errorf("range status %d body=%q", resp.StatusCode, strings.TrimSpace(string(body)))
			continue
		}

		if resp.StatusCode >= 200 && resp.StatusCode < 300 && end-start+1 == int64(len(body)) {
			// Server ignored Range and returned a 200 with exactly the bytes
			// we wanted — fine for the last chunk of a file, slightly off for
			// non-tail chunks. Caller decides; we return what we got.
			return body, nil
		}

		return nil, fmt.Errorf("range request status=%d body=%q", resp.StatusCode, strings.TrimSpace(string(body)))
	}

	if lastErr == nil {
		lastErr = errors.New("range chunk retries exhausted")
	}
	return nil, fmt.Errorf("range chunk retries exhausted: %w", lastErr)
}

// defaultResourceChunkSize returns the chunk size used when a Platform is
// constructed without going through newPlatform (tests, manual fixtures).
// Matches the production default of 8 MiB.
func defaultResourceChunkSize() int64 { return 8 * 1024 * 1024 }

// fetchResourceTokenOrDefault returns the bearer token used for resource
// downloads. Tests can inject a stub via Platform.fetchResourceToken;
// production callers fall through to fetchFreshTenantAccessToken which uses
// the lark SDK to mint a fresh tenant token on demand.
func (p *Platform) fetchResourceTokenOrDefault(ctx context.Context) (string, error) {

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Read the status code and body snippet: 401/403 → refresh or re-grant drive read credentials; 404 → re-fetch file metadata (file deleted/moved); 416 → recompute the range against a fresh file size
  2. Re-run the full download to obtain fresh metadata and tokens before resuming chunk fetches
  3. Verify the app/scopes have drive:drive.readonly (or equivalent) permission for the file
  4. If it happens mid-download repeatedly, shorten total download time or re-authenticate between chunks
Defensive patterns

Strategy: try-catch

Validate before calling

// before downloading, verify the app can still access the file
meta, err := fetchFileMeta(fileToken)
if err != nil { return fmt.Errorf("file %s not accessible: %w", fileToken, err) }

Try / catch

var httpErr *HTTPStatusError
if errors.As(err, &httpErr) {
    switch httpErr.StatusCode {
    case 401: refreshToken(); retry()
    case 403: requestDriveReadScope()
    case 404: reFetchFileMeta()
    case 416: recomputeRanges()
    }
}

Prevention

When it happens

Trigger: resourceFetchRemainingChunks -> resourceRangeChunk: response status is e.g. 401/403/404/416 or any non-2xx, or a 2xx whose body length does not match end-start+1; no retry applies so the error is returned immediately.

Common situations: Expired/insufficient drive read permission (403); file deleted or token revoked (404); invalid Range triggering 416; tenant policy blocking download; auth token expiring mid multi-chunk download.

Related errors


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