forked from alpacahq/alpaca-trade-api-csharp
/
RestClientErrorException.cs
91 lines (79 loc) · 2.71 KB
/
RestClientErrorException.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
using System.Net;
namespace Alpaca.Markets;
/// <summary>
/// Represents Alpaca REST and Streaming API specific error information.
/// </summary>
[Serializable]
public sealed class RestClientErrorException : Exception
{
/// <summary>
/// Creates new instance of <see cref="RestClientErrorException"/> class.
/// </summary>
public RestClientErrorException()
{
}
/// <summary>
/// Creates new instance of <see cref="RestClientErrorException"/> class with specified error message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public RestClientErrorException(
String message)
: base(message)
{
}
/// <summary>
/// Creates new instance of <see cref="RestClientErrorException"/> class with
/// specified error message and reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The message that describes the error.</param>
/// <param name="inner">The exception that is the cause of this exception.</param>
[ExcludeFromCodeCoverage]
public RestClientErrorException(
String message,
Exception inner)
: base(message, inner)
{
}
[ExcludeFromCodeCoverage]
private RestClientErrorException(
SerializationInfo info,
StreamingContext context)
: base(info, context)
{
}
internal RestClientErrorException(
HttpResponseMessage message,
JsonError error)
: base(error.Message)
{
ErrorInformation = error;
HttpStatusCode = message.StatusCode;
ErrorCode = error.Code ?? (Int32)HttpStatusCode;
}
internal RestClientErrorException(
JsonStreamError error)
: base(error.Message) =>
ErrorCode = error.Code;
internal RestClientErrorException(
HttpResponseMessage message)
: base(message.ReasonPhrase ?? String.Empty) =>
ErrorCode = (Int32)(HttpStatusCode = message.StatusCode);
[ExcludeFromCodeCoverage]
internal RestClientErrorException(
HttpResponseMessage message,
Exception exception)
: base(message.ReasonPhrase ?? String.Empty, exception) =>
ErrorCode = (Int32)(HttpStatusCode = message.StatusCode);
/// <summary>
/// Gets original error code returned by REST API endpoint.
/// </summary>
public Int32 ErrorCode { get; }
/// <summary>
/// Gets original HTTP status code returned by REST API endpoint.
/// </summary>
public HttpStatusCode? HttpStatusCode { get; }
/// <summary>
/// Gets extended error information if it provided by server.
/// </summary>
public IErrorInformation? ErrorInformation { get; }
}