2
using System.Collections.Generic;
3
using ServiceStack.Common.Utils;
4
using ServiceStack.ServiceInterface.ServiceModel;
5
using ServiceStack.Text;
7
namespace ServiceStack.ServiceClient.Web
9
public class WebServiceException
12
public WebServiceException() { }
13
public WebServiceException(string message) : base(message) { }
14
public WebServiceException(string message, Exception innerException) : base(message, innerException) { }
16
public int StatusCode { get; set; }
18
public string StatusDescription { get; set; }
20
public object ResponseDto { get; set; }
22
public string ResponseBody { get; set; }
24
private string errorCode;
26
private void ParseResponseDto()
28
if (ResponseDto == null)
30
errorCode = StatusDescription;
33
var jsv = TypeSerializer.SerializeToString(ResponseDto);
34
var map = TypeSerializer.DeserializeFromString<Dictionary<string, string>>(jsv);
35
map = new Dictionary<string, string>(map, StringComparer.InvariantCultureIgnoreCase);
36
string responseStatus;
37
if (!map.TryGetValue("ResponseStatus", out responseStatus)) return;
39
var rsMap = TypeSerializer.DeserializeFromString<Dictionary<string, string>>(responseStatus);
40
if (rsMap == null) return;
41
rsMap = new Dictionary<string, string>(rsMap, StringComparer.InvariantCultureIgnoreCase);
42
rsMap.TryGetValue("ErrorCode", out errorCode);
43
rsMap.TryGetValue("Message", out errorMessage);
44
rsMap.TryGetValue("StackTrace", out serverStackTrace);
47
public string ErrorCode
51
if (errorCode == null)
59
private string errorMessage;
60
public string ErrorMessage
64
if (errorMessage == null)
72
private string serverStackTrace;
73
public string ServerStackTrace
77
if (serverStackTrace == null)
81
return serverStackTrace;
85
public ResponseStatus ResponseStatus
89
if (this.ResponseDto == null)
92
var hasResponseStatus = this.ResponseDto as IHasResponseStatus;
93
if (hasResponseStatus != null)
94
return hasResponseStatus.ResponseStatus;
96
var propertyInfo = this.ResponseDto.GetType().GetProperty("ResponseStatus");
97
if (propertyInfo == null)
100
return ReflectionUtils.GetProperty(this.ResponseDto, propertyInfo) as ResponseStatus;
104
public List<ResponseError> GetFieldErrors()
106
var responseStatus = ResponseStatus;
107
if (responseStatus != null)
108
return responseStatus.Errors ?? new List<ResponseError>();
110
return new List<ResponseError>();