mirror of
https://github.com/Kopano-dev/kopano-ol-extension.git
synced 2023-10-10 13:37:40 +02:00
[KOE-187] Improved logging of Soap parsing errors
This commit is contained in:
parent
24ef5782c8
commit
955e2557f0
@ -49,6 +49,14 @@ namespace Acacia.ZPush.Connect.Soap
|
||||
|
||||
public string ServiceName { get; set; }
|
||||
|
||||
public override string RequestName
|
||||
{
|
||||
get
|
||||
{
|
||||
return _request.RequestName;
|
||||
}
|
||||
}
|
||||
|
||||
#region Encoding
|
||||
|
||||
private const string PREFIX = @"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
|
@ -87,6 +87,48 @@ namespace Acacia.ZPush.Connect.Soap
|
||||
|
||||
#region Builtin types
|
||||
|
||||
private class ConversionException : Exception
|
||||
{
|
||||
private readonly List<XmlNode> trace = new List<XmlNode>();
|
||||
|
||||
public ConversionException(XmlNode node, string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
AddNode(node);
|
||||
}
|
||||
|
||||
public void AddNode(XmlNode node)
|
||||
{
|
||||
trace.Add(node);
|
||||
}
|
||||
|
||||
public override string Message
|
||||
{
|
||||
get
|
||||
{
|
||||
string context = "";
|
||||
foreach(XmlNode node in trace)
|
||||
{
|
||||
int index = -1;
|
||||
int count = 0;
|
||||
if (node.ParentNode != null)
|
||||
{
|
||||
for (int i = 0; i < node.ParentNode.ChildNodes.Count; ++i)
|
||||
{
|
||||
if (node.ParentNode.ChildNodes[i].Name == node.Name)
|
||||
++count;
|
||||
if (node.ParentNode.ChildNodes[i] == node)
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
|
||||
string suffix = (index < 0 || count <= 1) ? "" : ("[" + index + "]");
|
||||
context = "/" + node.Name + suffix + context;
|
||||
}
|
||||
return base.Message + " @ " + context + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private abstract class TypeHandler
|
||||
{
|
||||
public string FullName
|
||||
@ -109,14 +151,32 @@ namespace Acacia.ZPush.Connect.Soap
|
||||
|
||||
public object Deserialize(XmlNode node, Type expectedType)
|
||||
{
|
||||
object value = DeserializeContents(node, expectedType);
|
||||
if (expectedType != null)
|
||||
object value = null;
|
||||
try
|
||||
{
|
||||
// Try to convert it to the expected type
|
||||
return SoapConvert(expectedType, value);
|
||||
}
|
||||
value = DeserializeContents(node, expectedType);
|
||||
if (expectedType != null)
|
||||
{
|
||||
// Try to convert it to the expected type
|
||||
return SoapConvert(expectedType, value);
|
||||
}
|
||||
|
||||
return value;
|
||||
return value;
|
||||
}
|
||||
catch(ConversionException e)
|
||||
{
|
||||
e.AddNode(node);
|
||||
throw e;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw new ConversionException(node,
|
||||
string.Format("Cannot convert value '{0}' to {1}",
|
||||
value ?? node.InnerXml, expectedType
|
||||
),
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,6 +26,11 @@ namespace Acacia.ZPush.Connect
|
||||
{
|
||||
public abstract class RequestEncoder
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of the request, for debug purposes.
|
||||
/// </summary>
|
||||
public abstract string RequestName { get; }
|
||||
|
||||
public abstract HttpContent GetContent();
|
||||
|
||||
public abstract object ParseResponse(string url, Stream result);
|
||||
|
Loading…
Reference in New Issue
Block a user