forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebServiceException.cs
More file actions
111 lines (95 loc) · 3.49 KB
/
WebServiceException.cs
File metadata and controls
111 lines (95 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using System.Collections.Generic;
using ServiceStack.Common.Utils;
using ServiceStack.ServiceInterface.ServiceModel;
using ServiceStack.Text;
namespace ServiceStack.ServiceClient.Web
{
public class WebServiceException
: Exception
{
public WebServiceException() { }
public WebServiceException(string message) : base(message) { }
public WebServiceException(string message, Exception innerException) : base(message, innerException) { }
public int StatusCode { get; set; }
public string StatusDescription { get; set; }
public object ResponseDto { get; set; }
private string errorCode;
private void ParseResponseDto()
{
if (ResponseDto == null)
{
errorCode = StatusDescription;
return;
}
var jsv = TypeSerializer.SerializeToString(ResponseDto);
var map = TypeSerializer.DeserializeFromString<Dictionary<string, string>>(jsv);
map = new Dictionary<string, string>(map, StringComparer.InvariantCultureIgnoreCase);
string responseStatus;
if (!map.TryGetValue("ResponseStatus", out responseStatus)) return;
var rsMap = TypeSerializer.DeserializeFromString<Dictionary<string, string>>(responseStatus);
if (rsMap == null) return;
rsMap = new Dictionary<string, string>(rsMap, StringComparer.InvariantCultureIgnoreCase);
rsMap.TryGetValue("ErrorCode", out errorCode);
rsMap.TryGetValue("Message", out errorMessage);
rsMap.TryGetValue("StackTrace", out serverStackTrace);
}
public string ErrorCode
{
get
{
if (errorCode == null)
{
ParseResponseDto();
}
return errorCode;
}
}
private string errorMessage;
public string ErrorMessage
{
get
{
if (errorMessage == null)
{
ParseResponseDto();
}
return errorMessage;
}
}
private string serverStackTrace;
public string ServerStackTrace
{
get
{
if (serverStackTrace == null)
{
ParseResponseDto();
}
return serverStackTrace;
}
}
public ResponseStatus ResponseStatus
{
get
{
if (this.ResponseDto == null)
return null;
var hasResponseStatus = this.ResponseDto as IHasResponseStatus;
if (hasResponseStatus != null)
return hasResponseStatus.ResponseStatus;
var propertyInfo = this.ResponseDto.GetType().GetProperty("ResponseStatus");
if (propertyInfo == null)
return null;
return ReflectionUtils.GetProperty(this.ResponseDto, propertyInfo) as ResponseStatus;
}
}
public List<ResponseError> GetFieldErrors()
{
var responseStatus = ResponseStatus;
if (responseStatus != null)
return responseStatus.Errors ?? new List<ResponseError>();
return new List<ResponseError>();
}
}
}