Skip to content

Commit

Permalink
Fail on http errors (>=300) for cURL downloads.
Browse files Browse the repository at this point in the history
  • Loading branch information
DasSkelett committed Sep 30, 2019
1 parent 05406ba commit a5574bc
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions Core/Net/Net.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down

0 comments on commit a5574bc

Please sign in to comment.