{"record":{"id":"036f3a2522b1ff93","repo":"subhra74/xdm","slug":"invalid-response-code-statuscode-value","errorCode":null,"errorMessage":"Invalid response code: {statusCode.Value}","messagePattern":"Invalid response code: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"app/XDM/XDM.Core/Downloader/Adaptive/Hls/MultiSourceHLSDownloader.cs","lineNumber":188,"sourceCode":"                    if (status.Length == 2)\r\n                    {\r\n                        if (status[0] != HttpStatusCode.OK) return status[0];\r\n                        if (status[1] != HttpStatusCode.OK) return status[1];\r\n                        return null;\r\n                    }\r\n                    else\r\n                    {\r\n                        if (status[0] != HttpStatusCode.OK) return status[0];\r\n                        return null;\r\n                    }\r\n                }\r\n\r\n                if (!success)\r\n                {\r\n                    var statusCode = FindErrorStatus();\r\n                    if (statusCode.HasValue)\r\n                    {\r\n                        throw new Exception($\"Invalid response code: {statusCode.Value}\",\r\n                            new HttpException(statusCode.Value.ToString(), null, statusCode.Value));\r\n                    }\r\n                    throw new Exception(\"Unable to download HLS manifest\");\r\n                }\r\n\r\n                var playlists = new Dictionary<string, HlsPlaylist>();\r\n                if (state.Demuxed)\r\n                {\r\n                    playlists[\"video\"] = HlsParser.ParseMediaSegments(results[0]!.Split('\\n'), state.NonMuxedVideoPlaylistUrl.ToString());\r\n                    playlists[\"audio\"] = HlsParser.ParseMediaSegments(results[1]!.Split('\\n'), state.NonMuxedAudioPlaylistUrl.ToString());\r\n\r\n                    this._state.VideoContainerFormat = GuessContainerFormatFromPlaylist(playlists[\"video\"]);\r\n                    this._state.AudioContainerFormat = GuessContainerFormatFromPlaylist(playlists[\"audio\"]);\r\n                    \r\n                    var ext = FileExtensionHelper.GuessContainerFormatFromSegmentExtension(\r\n                            this._state.VideoContainerFormat, this._state.AudioContainerFormat);\r\n                    TargetFileName = Path.GetFileNameWithoutExtension(TargetFileName ?? \"video\")\r\n                            + ext;\r","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/subhra74/xdm/blob/1ca5a25aae007826c859c81bea494e7c102e1242/app/XDM/XDM.Core/Downloader/Adaptive/Hls/MultiSourceHLSDownloader.cs#L170-L206","documentation":"MultiSourceHLSDownloader.ProbeTarget downloads the HLS manifest and, when the download fails, inspects captured HTTP error statuses via FindErrorStatus. If a status code was recorded it throws an Exception 'Invalid response code: N' with an inner HttpException carrying that status.","triggerScenarios":"ProbeTarget (invoked while building the playlists dictionary) receives failed segment/manifest downloads and FindErrorStatus() returns a known HTTP error status, e.g. 403/404 from the HLS server.","commonSituations":"HLS master/media playlist URL returns 403 due to expired tokens/signed URLs; 404 because the playlist was removed; CDN geo-blocking; rate limiting (429) under heavy segment requests.","solutions":["Read the inner HttpException's status code: 403/401 means refresh cookies or signed URLs from the browser, 404 means the manifest URL is stale","Re-extract the m3u8 URL from the page; CDN playlists rotate and old URLs expire quickly","Retry with backoff if the code is 429/5xx (rate limiting or transient server issues)","Ensure required headers (Referer, User-Agent, Origin) captured with the video match what the CDN expects"],"exampleFix":"// before\nthrow new Exception($\"Invalid response code: {statusCode.Value}\",\n    new HttpException(statusCode.Value.ToString(), null, statusCode.Value));\n// after\nvar code = (int)statusCode.Value;\nif (code == 403 || code == 401)\n    throw new DownloadException(ErrorCode.AuthExpired, $\"HLS manifest auth failed ({code}) - refresh URL/cookies\");\nthrow new Exception($\"Invalid response code: {statusCode.Value}\",\n    new HttpException(statusCode.Value.ToString(), null, statusCode.Value));","handlingStrategy":"try-catch","validationCode":"// Pre-flight the manifest URL before probing\nusing (var resp = await http.GetAsync(manifestUrl))\n{\n    if (!resp.IsSuccessStatusCode)\n        Log.Warn($\"HLS manifest pre-check failed: {(int)resp.StatusCode}\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    downloader.ProbeTarget();\n}\ncatch (Exception ex) when (ex.InnerException is HttpException he)\n{\n    int code = (int)he.StatusCode;\n    if (code == 401 || code == 403) RefreshSignedUrl();\n    else if (code == 429) await Task.Delay(TimeSpan.FromSeconds(30));\n    throw;\n}","preventionTips":["Re-capture m3u8 URLs shortly before download; signed CDN URLs expire fast","Send the same Referer/User-Agent/Origin headers the player used","Back off and retry on 429/5xx responses","Test the manifest URL with curl before starting the HLS download"],"tags":["http","hls","streaming","download"],"backgroundTag":"http-error-response","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"}