{"record":{"id":"4eaab3df07c92c76","repo":"subhra74/xdm","slug":"invalidresponse","errorCode":"InvalidResponse","errorMessage":"Invalid response: {e.Message}","messagePattern":"Invalid response: (.+?)","errorType":"error_code","errorClass":"DownloadException","httpStatus":null,"severity":"error","filePath":"app/XDM/XDM.Core/Downloader/Progressive/PieceGrabber.cs","lineNumber":103,"sourceCode":"                            }\r\n                            connectPhase = false;\r\n                            this.Download(response);\r\n                        }\r\n\r\n                        OnComplete();\r\n                        return;\r\n                    }\r\n                    catch (TextRedirectException e)\r\n                    {\r\n                        this.redirectUri = e.RedirectUri;\r\n                        continue;\r\n                    }\r\n                    catch (HttpException e)\r\n                    {\r\n                        var status = e.StatusCode;\r\n                        if (Enum.IsDefined(typeof(HttpStatusCode), status))\r\n                        {\r\n                            throw new DownloadException(ErrorCode.InvalidResponse,\r\n                                \"Invalid response: \" + e.Message, e);\r\n                        }\r\n                    }\r\n                    catch (Exception e)\r\n                    {\r\n                        if (e is KeyNotFoundException || this.CancellationToken.IsCancellationRequested) return;\r\n                        if (e is AssembleFailedException || e is NonRetriableException || e is OperationCanceledException) throw;\r\n                        Log.Debug(e, \"Error in PieceGrabber inner block - swallowing error - isCancelled: \" + this.cancellationTokenSource.IsCancellationRequested);\r\n                    }\r\n                    timesRetried++;\r\n                    if (timesRetried > Config.Instance.MaxRetry)\r\n                    {\r\n                        throw new DownloadException(ErrorCode.MaxRetryFailed, \"Max retry exceeded\");\r\n                    }\r\n                    if (connectPhase)\r\n                    {\r\n                        sleep(Config.Instance.RetryDelay * 1000);\r\n                        CancellationToken.ThrowIfCancellationRequested();\r","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/subhra74/xdm/blob/1ca5a25aae007826c859c81bea494e7c102e1242/app/XDM/XDM.Core/Downloader/Progressive/PieceGrabber.cs#L85-L121","documentation":"PieceGrabber.Download2 catches HttpException thrown by the HTTP response validation and, when the status code is a defined HttpStatusCode, rethrows it as a DownloadException with ErrorCode.InvalidResponse and message 'Invalid response: <original message>'. This converts raw HTTP failures during piece download into a typed download error.","triggerScenarios":"Download2 requests a byte-range piece and the server responds with a non-success status (via EnsureSuccessStatusCode), whose message is wrapped into DownloadException(ErrorCode.InvalidResponse).","commonSituations":"Server returns 403/404 for range requests because the URL or signed token expired mid-download; 416 Range Not Satisfiable on bad resume offsets; 5xx from overloaded servers; CDN dropping support for the requested range.","solutions":["Check the wrapped HttpException's StatusCode: 403/401 means re-fetch fresh URL/cookies; 416 means reset the resume offset and restart the piece","Retry the piece download with fresh headers; signed CDN URLs frequently expire between segments","For persistent 4xx/5xx, restart the whole download so PieceGrabber re-resolves the source URL","Verify the server supports byte-range requests (Accept-Ranges); fall back to single-connection download if not"],"exampleFix":"// before\ncatch (HttpException e)\n{\n    var status = e.StatusCode;\n    if (Enum.IsDefined(typeof(HttpStatusCode), status))\n        throw new DownloadException(ErrorCode.InvalidResponse, \"Invalid response: \" + e.Message, e);\n}\n// after\ncatch (HttpException e)\n{\n    var status = e.StatusCode;\n    if (Enum.IsDefined(typeof(HttpStatusCode), status))\n    {\n        if ((int)status == 403 || (int)status == 401) RefreshSourceUrlAndCookies();\n        if ((int)status == 416) ResetPieceOffsets();\n        throw new DownloadException(ErrorCode.InvalidResponse,\n            $\"Invalid response ({(int)status}): {e.Message}\", e);\n    }\n}","handlingStrategy":"retry","validationCode":"// Pre-check the piece URL and range support before Download2\nvar req = (HttpWebRequest)WebRequest.Create(pieceUrl);\nreq.Method = \"HEAD\";\nusing (var resp = (HttpWebResponse)await req.GetResponseAsync())\n{\n    bool supportsRanges = resp.Headers[HttpResponseHeader.AcceptRanges] == \"bytes\";\n    if (!supportsRanges) FallBackToSingleConnectionDownload();\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    grabber.Download2(...);\n}\ncatch (DownloadException de) when (de.ErrorCode == ErrorCode.InvalidResponse)\n{\n    var http = (HttpException)de.InnerException;\n    if ((int)http.StatusCode == 403 || (int)http.StatusCode == 401)\n        RefreshUrlAndCookiesThenRetry();\n    else if ((int)http.StatusCode == 416)\n        ResetResumeOffsetsThenRetry();\n    else\n        throw;\n}","preventionTips":["Refresh signed/expiring URLs and cookies between piece downloads","Verify the server supports byte ranges (Accept-Ranges: bytes) before multi-piece downloading","Reset resume offsets after 416 Range Not Satisfiable responses","Retry pieces on 5xx/429 with backoff before failing the whole download"],"tags":["http","download","http-status","pieces"],"backgroundTag":"invalid-argument-value","analyzedSha":"1ca5a25aae007826c859c81bea494e7c102e1242","analyzedAt":"2026-09-13T20:37:40.968Z","contentChangedAt":"2026-09-13T20:37:40.968Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}