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; } } }