Fixed IgnoreResponseErrors

This commit is contained in:
ruri
2020-03-27 02:46:52 +01:00
3 changed files with 59 additions and 7 deletions
+43 -2
View File
@@ -168,7 +168,35 @@ namespace RuriLib
http.Timeout = TimeSpan.FromMinutes(timeout);
http.DefaultRequestHeaders.Add("User-Agent", ReplaceValues(UserAgent, data));
var result = cf.Solve(http, handler, uri, ReplaceValues(UserAgent, data)).Result;
SolveResult result = new SolveResult();
try
{
result = cf.Solve(http, handler, uri, ReplaceValues(UserAgent, data)).Result;
}
catch (AggregateException ex)
{
// Join all the aggregate exception inner exception messages
var message = string.Join(Environment.NewLine, ex.InnerExceptions.Select(e => e.Message));
if (data.ConfigSettings.IgnoreResponseErrors)
{
data.Log(new LogEntry(message, Colors.Tomato));
data.ResponseCode = message;
return;
}
throw new Exception(message);
}
catch (Exception ex)
{
if (data.ConfigSettings.IgnoreResponseErrors)
{
data.Log(new LogEntry(ex.Message, Colors.Tomato));
data.ResponseSource = ex.Message;
return;
}
throw;
}
if (result.Success)
{
@@ -180,7 +208,15 @@ namespace RuriLib
}
else
{
throw new Exception($"CF Bypass Failed: {result.FailReason}");
var message = $"CF Bypass Failed: {result.FailReason}";
if (data.ConfigSettings.IgnoreResponseErrors)
{
data.Log(new LogEntry(message, Colors.Tomato));
data.ResponseSource = message;
return;
}
throw new Exception(message);
}
// Now that we got the cookies, proceed with the normal request
@@ -191,6 +227,11 @@ namespace RuriLib
}
catch (Exception ex)
{
if (data.ConfigSettings.IgnoreResponseErrors)
{
data.ResponseSource = ex.Message;
return;
}
throw new Exception(ex.Message);
}
finally
+14 -1
View File
@@ -412,7 +412,20 @@ namespace RuriLib
data.LogNewLine();
// Perform the request
(data.Address, data.ResponseCode, data.ResponseHeaders, data.Cookies) = request.Perform(localUrl, Method, data.ConfigSettings.IgnoreResponseErrors, GetLogBuffer(data));
try
{
(data.Address, data.ResponseCode, data.ResponseHeaders, data.Cookies) = request.Perform(localUrl, Method, GetLogBuffer(data));
}
catch (Exception ex)
{
if (data.ConfigSettings.IgnoreResponseErrors)
{
data.Log(new LogEntry(ex.Message, Colors.Tomato));
data.ResponseSource = ex.Message;
return;
}
throw;
}
// Save the response content
switch (ResponseType)
+2 -4
View File
@@ -234,11 +234,9 @@ namespace RuriLib.Functions.Requests
/// </summary>
/// <param name="url">The URL</param>
/// <param name="method">The HTTP method</param>
/// <param name="ignoreErrors">Whether to ignore response errors</param>
/// <param name="log">The log (if any)</param>
/// <returns>A 4-tuple containing Address, Response code, Headers and Cookies.</returns>
public (string, string, Dictionary<string, string>, Dictionary<string, string>) Perform(string url, HttpMethod method,
bool ignoreErrors = false, List<LogEntry> log = null)
public (string, string, Dictionary<string, string>, Dictionary<string, string>) Perform(string url, HttpMethod method, List<LogEntry> log = null)
{
var address = "";
var responseCode = "0";
@@ -295,7 +293,7 @@ namespace RuriLib.Functions.Requests
if (log != null) log.Add(new LogEntry("Status code: " + responseCode, Colors.Cyan));
}
if (!ignoreErrors) throw;
throw;
}
return (address, responseCode, headers, cookies);