{"record":{"id":"436868723fc10f3f","repo":"chenhg5/cc-connect","slug":"download-failed-with-status-d-s","errorCode":null,"errorMessage":"download failed with status %d: %s","messagePattern":"download failed with status (.+?): (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/slack/slack.go","lineNumber":577,"sourceCode":"\nvar _ core.FileSender = (*Platform)(nil)\n\nfunc (p *Platform) downloadSlackFile(url string) ([]byte, error) {\n\tif url == \"\" {\n\t\treturn nil, fmt.Errorf(\"empty URL\")\n\t}\n\treq, _ := http.NewRequest(\"GET\", url, nil)\n\treq.Header.Set(\"Authorization\", \"Bearer \"+p.botToken)\n\tresp, err := core.HTTPClient.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"%s\", core.RedactToken(err.Error(), p.botToken))\n\t}\n\tdefer resp.Body.Close()\n\n\t// Check if we got an unexpected status code (e.g., redirect to login page)\n\tif resp.StatusCode != http.StatusOK {\n\t\tbody, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))\n\t\treturn nil, fmt.Errorf(\"download failed with status %d: %s\", resp.StatusCode, string(body))\n\t}\n\n\tdata, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read response body: %w\", err)\n\t}\n\n\t// Basic sanity check: detect if we received HTML instead of binary data\n\tif len(data) > 0 && (bytes.HasPrefix(data, []byte(\"<!DOCTYPE\")) || bytes.HasPrefix(data, []byte(\"<html\"))) {\n\t\treturn nil, fmt.Errorf(\"received HTML response (likely missing auth); first 100 bytes: %s\", string(data[:min(100, len(data))]))\n\t}\n\n\treturn data, nil\n}\n\nfunc (p *Platform) ReconstructReplyCtx(sessionKey string) (any, error) {\n\t// slack:{channel}:{user}  |  slack:{channel}:t:{threadTS}  |  slack:{channel}\n\tparts := strings.SplitN(sessionKey, \":\", 3)","sourceCodeStart":559,"sourceCodeEnd":595,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/slack/slack.go#L559-L595","documentation":"downloadSlackFile: non-200 response — often a redirect to a login page when the Bearer authorization header was missing or rejected; the first 1KB of the body is embedded so HTML login pages are visible in the error.","triggerScenarios":"Thrown at platform/slack/slack.go:577 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the 'Bearer '+botToken header is sent","Check the token has files:read scope"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}