From a5574bc10bcd6fb9a4b39d851adfffd2710bce75 Mon Sep 17 00:00:00 2001 From: DasSkelett Date: Mon, 30 Sep 2019 23:34:35 +0200 Subject: [PATCH] Fail on http errors (>=300) for cURL downloads. As per https://github.com/masroore/CurlSharp/blob/f9da9aefbc2e26e7ad9e1a242a45e9277b1fc82d/CurlSharp/Enums/CurlOption.cs#L224-L229. This should prevent download errors being concealed. --- Core/Net/Net.cs | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/Core/Net/Net.cs b/Core/Net/Net.cs index 62c610a5c3..3e2a880cb7 100644 --- a/Core/Net/Net.cs +++ b/Core/Net/Net.cs @@ -243,37 +243,37 @@ public static string DownloadText(Uri url, string authToken = "") return agent.DownloadString(url.OriginalString); } - catch (Exception) + catch (Exception e) { - try - { - log.InfoFormat("Download failed, trying with curlsharp..."); + log.InfoFormat(e.ToString()); + log.InfoFormat("Download failed, trying with curlsharp..."); - var content = string.Empty; + var content = string.Empty; - var client = Curl.CreateEasy(url.OriginalString, delegate (byte[] buf, int size, int nmemb, object extraData) - { - content += Encoding.UTF8.GetString(buf); - return size * nmemb; - }); + var client = Curl.CreateEasy(url.OriginalString, delegate (byte[] buf, int size, int nmemb, object extraData) + { + content += Encoding.UTF8.GetString(buf); + return size * nmemb; + }); - using (client) - { - var result = client.Perform(); + client.SetOpt(CurlOption.FailOnError, true); + + using (client) + { + var result = client.Perform(); + var returnCode = client.ResponseCode; - if (result != CurlCode.Ok) - { - throw new Exception("Curl download failed with error " + result); - } + if (result != CurlCode.Ok) + { + throw new WebException( + String.Format("Curl download failed with error {0} ({1})", result, returnCode), + e + ); + } - log.DebugFormat("Download from {0}:\r\n\r\n{1}", url, content); + log.DebugFormat("Download from {0}:\r\n\r\n{1}", url, content); - return content; - } - } - catch (Exception e) - { - throw new Kraken("Downloading using cURL failed", e); + return content; } } }