{"record":{"id":"2eddd139b604e8e8","repo":"NickeManarin/ScreenToGif","slug":"unsuccessful-download-of-stream","errorCode":null,"errorMessage":"Unsuccessful download of stream.","messagePattern":"Unsuccessful download of stream\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"ScreenToGif.Util/WebHelper.cs","lineNumber":248,"sourceCode":"                throw;\n\n            return resp;\n        }\n        catch (Exception ex)\n        {\n            LogWriter.Log(ex, \"Get response: \" + url);\n        }\n\n        return null;\n    }\n\n    public static async Task<Stream> GetStream(string url, NameValueCollection headers = null)\n    {\n        using var client = GetHttpClient(headers);\n        var response = await client.GetAsync(url);\n\n        if (!response.IsSuccessStatusCode)\n            throw new Exception(\"Unsuccessful download of stream.\");\n\n        return await response.Content.ReadAsStreamAsync();\n    }\n\n\n    private static HttpWebRequest GetWebRequest(HttpMethod method, string url, NameValueCollection headers = null, string contentType = null, long contentLength = 0)\n    {\n        var request = (HttpWebRequest) WebRequest.Create(url);\n\n        if (headers != null)\n            request.Headers.Add(headers);\n\n        request.Method = method.ToString();\n        request.Proxy = GetProxy();\n        request.UserAgent = \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393\";\n        request.ContentType = contentType;\n\n        if (contentLength == 0)","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/NickeManarin/ScreenToGif/blob/a4d0a67c2131cd048ceec86cd40afc2f1a06f2fd/ScreenToGif.Util/WebHelper.cs#L230-L266","documentation":"Thrown by WebHelper.GetStream when an HTTP GET returns a non-success status code. Unlike the GitHub helper, this method does not include the status code or URL in the message — it simply reports 'Unsuccessful download of stream'. The method is a generic stream downloader used across the application.","triggerScenarios":"client.GetAsync(url) returns a non-2xx response for any URL passed to GetStream. This could be a 404 (resource not found), 403 (forbidden), 500 (server error), or any other error. The URL, headers, or proxy configuration may be wrong.","commonSituations":"Downloaded resource URL changed or was removed. Proxy or firewall blocks the request. Server requires authentication that wasn't provided. SSL/TLS certificate issue causes a failure. The NameValueCollection headers are missing a required header (e.g., User-Agent).","solutions":["Include the URL and status code in the exception message for debugging.","Log the response.StatusCode and response.ReasonPhrase before throwing.","Verify the URL is correct and accessible from a browser or curl.","Ensure required headers (User-Agent, Authorization) are passed via the headers parameter."],"exampleFix":"// before\nif (!response.IsSuccessStatusCode)\n    throw new Exception(\"Unsuccessful download of stream.\");\n\n// after: include URL and status code\nif (!response.IsSuccessStatusCode)\n    throw new HttpRequestException($\"Unsuccessful download of stream from '{url}': {(int)response.StatusCode} {response.ReasonPhrase}\");","handlingStrategy":"try-catch","validationCode":"// Pre-validate URL format and reachability\nif (!Uri.TryCreate(url, UriKind.Absolute, out var uri))\n    throw new ArgumentException($\"Invalid URL: {url}\");\nif (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps)\n    throw new ArgumentException(\"Only HTTP/HTTPS URLs are supported.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    return await WebHelper.GetStream(url, headers);\n}\ncatch (Exception ex)\n{\n    LogWriter.Log(ex, $\"Failed to download stream from {url}\");\n    throw new InvalidOperationException($\"Download failed for '{url}': {ex.Message}\", ex);\n}","preventionTips":["Always pass a User-Agent header to avoid being blocked by servers.","Log the URL and HTTP status code when the download fails for easier debugging.","Validate the URL is well-formed and uses HTTP/HTTPS before calling GetStream."],"tags":["network","http","download","stream","webhelper"],"backgroundTag":null,"analyzedSha":"a4d0a67c2131cd048ceec86cd40afc2f1a06f2fd","analyzedAt":"2026-08-13T11:12:06.147Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}