-
Notifications
You must be signed in to change notification settings - Fork 41
/
ApiCommunicationException.cs
136 lines (127 loc) · 4.8 KB
/
ApiCommunicationException.cs
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Runtime.Serialization;
using System.Text;
namespace MYOB.AccountRight.SDK
{
/// <summary>
/// An exception that is thrown when there is a communication error i.e. web between the SDK and the account right servers
/// </summary>
#if !PORTABLE
[Serializable]
#endif
public class ApiCommunicationException : Exception
{
#if !PORTABLE
/// <summary>
/// Allow the ApiCommunicationException to be de-serialized
/// </summary>
/// <param name="info"></param>
/// <param name="context"></param>
protected ApiCommunicationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
StatusCode = (HttpStatusCode)info.GetInt32("StatusCode");
URI = (Uri)info.GetValue("URI", typeof(Uri));
Errors = (IList<Error>)info.GetValue("Errors", typeof(IList<Error>));
ErrorInformation = info.GetString("ErrorInformation");
RequestId = info.GetString("RequestId");
}
#endif
/// <summary>
/// A standard HTTP status
/// </summary>
public HttpStatusCode StatusCode { get; private set; }
/// <summary>
/// The URI of the service being accessed at the time
/// </summary>
public Uri URI { get; private set; }
/// <summary>
/// A list of errors extracted from the payload
/// </summary>
public IList<Error> Errors { get; private set; }
/// <summary>
/// Some extra error information
/// </summary>
public string ErrorInformation { get; private set; }
/// <summary>
///
/// </summary>
public string RequestId { get; private set; }
/// <summary>
/// Initializes an instance of the ApiCommunicationException class
/// </summary>
/// <param name="message"></param>
/// <param name="statusCode"></param>
/// <param name="uri"></param>
/// <param name="innerException"></param>
/// <param name="listOfErrors"></param>
/// <param name="information"></param>
/// <param name="requestId"></param>
public ApiCommunicationException(string message, HttpStatusCode statusCode, Uri uri, WebException innerException, IList<Error> listOfErrors, string information, string requestId)
: base(message, innerException)
{
StatusCode = statusCode;
URI = uri;
Errors = listOfErrors;
ErrorInformation = information;
RequestId = requestId;
}
#if !PORTABLE
/// <summary>
/// Allow the ApiCommunicationException to be serialized
/// </summary>
/// <param name="info"></param>
/// <param name="context"></param>
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("StatusCode", (int)StatusCode);
info.AddValue("URI", URI);
info.AddValue("Errors", Errors);
info.AddValue("ErrorInformation", ErrorInformation);
info.AddValue("RequestId", RequestId);
}
#endif
}
/// <summary>
/// An exception that is thrown when an error has occured within the API and is not communication related
/// </summary>
#if !PORTABLE
[Serializable]
#endif
public class ApiOperationException : Exception
{
/// <summary>
/// Initializes an instance of the ApiOperationException class
/// </summary>
/// <param name="message"></param>
/// <param name="innerException"></param>
public ApiOperationException(string message, Exception innerException) : base(message,innerException){}
}
/// <summary>
/// An exception that is thrown when the API throws a validation exception
/// </summary>
#if !PORTABLE
[Serializable]
#endif
public class ApiValidationException : ApiCommunicationException
{
/// <summary>
/// Initializes an instance of the ApiCommunicationException class
/// </summary>
/// <param name="message"></param>
/// <param name="statusCode"></param>
/// <param name="uri"></param>
/// <param name="innerException"></param>
/// <param name="listOfErrors"></param>
/// <param name="information"></param>
/// <param name="requestId"></param>
public ApiValidationException(string message, HttpStatusCode statusCode, Uri uri, WebException innerException, IList<Error> listOfErrors, string information, string requestId)
: base(message, statusCode, uri, innerException, listOfErrors, information, requestId)
{
}
}
}