Skip to content

Commit

Permalink
Override WebServiceException to dump human friendlier remote error
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Dec 18, 2015
1 parent 1d4f8ee commit ee309c6
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/ServiceStack.Client/WebServiceException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Net;
using System.Runtime.Serialization;
using System.Text;
using ServiceStack.Text;

namespace ServiceStack
Expand Down Expand Up @@ -162,5 +163,49 @@ public bool IsAny500()
{
return StatusCode >= 500 && StatusCode < 600;
}

public override string ToString()
{
var sb = new StringBuilder();
sb.AppendFormat("{0} {1}\n", StatusCode, StatusDescription);
sb.AppendFormat("Code: {0}, Message: {1}\n", ErrorCode, ErrorMessage);

var status = ResponseStatus;
if (status != null)
{
if (!status.Errors.IsNullOrEmpty())
{
sb.Append("Field Errors:\n");
foreach (var error in status.Errors)
{
sb.AppendFormat(" [{0}] {1}:{2}\n", error.FieldName, error.ErrorCode, error.Message);

if (error.Meta != null && error.Meta.Count > 0)
{
sb.Append(" Field Meta:\n");
foreach (var entry in error.Meta)
{
sb.AppendFormat(" {0}:{1}\n", entry.Key, entry.Value);
}
}
}
}

if (status.Meta != null && status.Meta.Count > 0)
{
sb.Append("Meta:\n");
foreach (var entry in status.Meta)
{
sb.AppendFormat(" {0}:{1}\n", entry.Key, entry.Value);
}
}
}

if (!string.IsNullOrEmpty(ServerStackTrace))
sb.AppendFormat("Server StackTrace:\n {0}\n", ServerStackTrace);


return sb.ToString();
}
}
}

0 comments on commit ee309c6

Please sign in to comment.