When error happen while uploading, write request URL to error log

This commit is contained in:
Jaex 2017-01-23 09:32:30 +03:00
parent 72936e6795
commit 5dd11e6641

View file

@ -259,7 +259,7 @@ public virtual void StopUpload()
throw; throw;
} }
string response = AddWebError(e); string response = AddWebError(e, url);
if (WebExceptionReturnResponse && e is WebException) if (WebExceptionReturnResponse && e is WebException)
{ {
@ -317,7 +317,7 @@ public virtual void StopUpload()
throw; throw;
} }
AddWebError(e); AddWebError(e, url);
} }
} }
finally finally
@ -536,15 +536,22 @@ protected NameValueCollection CreateAuthenticationHeader(string username, string
return headers; return headers;
} }
private string AddWebError(Exception e) private string AddWebError(Exception e, string url)
{ {
string response = null; string response = null;
if (Errors != null && e != null) if (Errors != null && e != null)
{ {
StringBuilder str = new StringBuilder(); StringBuilder sb = new StringBuilder();
str.AppendLine("Message:"); sb.AppendLine("Message:");
str.AppendLine(e.Message); sb.AppendLine(e.Message);
if (!string.IsNullOrEmpty(url))
{
sb.AppendLine();
sb.AppendLine("Request URL:");
sb.AppendLine(url);
}
if (e is WebException) if (e is WebException)
{ {
@ -554,9 +561,9 @@ private string AddWebError(Exception e)
if (!string.IsNullOrEmpty(response)) if (!string.IsNullOrEmpty(response))
{ {
str.AppendLine(); sb.AppendLine();
str.AppendLine("Response:"); sb.AppendLine("Response:");
str.AppendLine(response); sb.AppendLine(response);
} }
} }
catch catch
@ -564,11 +571,11 @@ private string AddWebError(Exception e)
} }
} }
str.AppendLine(); sb.AppendLine();
str.AppendLine("StackTrace:"); sb.AppendLine("Stack trace:");
str.AppendLine(e.StackTrace); sb.AppendLine(e.StackTrace);
string errorText = str.ToString().Trim(); string errorText = sb.ToString().Trim();
Errors.Add(errorText); Errors.Add(errorText);
DebugHelper.WriteLine("Error:\r\n" + errorText); DebugHelper.WriteLine("Error:\r\n" + errorText);
} }