{"record":{"id":"6cd57ec11058549d","repo":"chenhg5/cc-connect","slug":"download-file-s-status-d","errorCode":null,"errorMessage":"download file %s: status %d","messagePattern":"download file (.+?): status (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/telegram/telegram.go","lineNumber":1366,"sourceCode":"\t\treturn nil, err\n\t}\n\tctx := context.Background()\n\tf, err := bot.GetFile(ctx, &tgbot.GetFileParams{FileID: fileID})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"get file: %w\", err)\n\t}\n\tif f.FilePath == \"\" {\n\t\treturn nil, fmt.Errorf(\"get file: empty file_path returned for file_id %s\", fileID)\n\t}\n\tlink := bot.FileDownloadLink(f)\n\n\tresp, err := p.httpClient.Get(link)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"download file %s: %w\", fileID, err)\n\t}\n\tdefer resp.Body.Close()\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"download file %s: status %d\", fileID, resp.StatusCode)\n\t}\n\treturn io.ReadAll(resp.Body)\n}\n\nfunc (p *Platform) ReconstructReplyCtx(sessionKey string) (any, error) {\n\t// Formats:\n\t//   telegram:{chatID}                      - shared session, no topic\n\t//   telegram:{chatID}:{threadID}           - shared session, with topic\n\t//   telegram:{chatID}:{userID}             - per-user session, no topic\n\t//   telegram:{chatID}:{threadID}:{userID}  - per-user session, with topic\n\tparts := strings.SplitN(sessionKey, \":\", 5)\n\tif len(parts) < 2 || parts[0] != \"telegram\" {\n\t\treturn nil, fmt.Errorf(\"telegram: invalid session key %q\", sessionKey)\n\t}\n\tchatID, err := strconv.ParseInt(parts[1], 10, 64)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"telegram: invalid chat ID in %q\", sessionKey)\n\t}","sourceCodeStart":1348,"sourceCodeEnd":1384,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/telegram/telegram.go#L1348-L1384","documentation":"Returned when the file download HTTP request completes but the status code is not 200 OK. The body may contain an error page or nothing useful, so the platform refuses to parse it and reports the exact status code alongside the file_id.","triggerScenarios":"p.httpClient.Get(link) succeeds but resp.StatusCode != http.StatusOK — e.g. 404 for an expired/invalid file path, 400 bad request, 5xx from Telegram's file server.","commonSituations":"Stale file_path: Telegram file paths expire after about an hour, so late downloads get 400/404; malformed link from an empty/odd file_path; Telegram file-server incidents returning 5xx.","solutions":["Re-fetch the file via getFile to obtain a fresh file_path immediately before downloading — paths expire (~1 hour TTL).","Check the status code in the message: 404/400 usually means expired or wrong path; 5xx means retry later.","Retry with exponential backoff on 5xx responses.","Confirm bot.FileDownloadLink builds the URL correctly for your bot API client version."],"exampleFix":"// before\nlink := bot.FileDownloadLink(f) // possibly stale\nresp, _ := p.httpClient.Get(link)\n// after: refresh metadata right before download\nf, err := bot.GetFile(ctx, &tgbot.GetFileParams{FileID: fileID})\nif err != nil { return nil, err }\nresp, err := p.httpClient.Get(bot.FileDownloadLink(f))","handlingStrategy":"retry","validationCode":"// download immediately after getFile; paths expire (~1h TTL)\nif time.Since(fetchedAt) > time.Hour { /* re-run GetFile */ }","typeGuard":null,"tryCatchPattern":"resp, err := p.httpClient.Get(link)\nif err != nil { return nil, err }\ndefer resp.Body.Close()\nif resp.StatusCode == http.StatusNotFound || resp.StatusCode == http.StatusBadRequest {\n    // refresh file_path via GetFile, then retry once\n}\nif resp.StatusCode != http.StatusOK {\n    return nil, fmt.Errorf(\"download file %s: status %d\", fileID, resp.StatusCode)\n}","preventionTips":["Re-run getFile right before downloading to avoid expired file paths","Retry 5xx responses with backoff","Treat 400/404 as a signal to refresh file metadata","Verify FileDownloadLink URL construction for your client version"],"tags":["telegram","http","file-download","status-code"],"backgroundTag":"http-non-200-response","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"}