/
HttpRequestException.cs
72 lines (63 loc) · 3.09 KB
/
HttpRequestException.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace System.Net.Http
{
public class HttpRequestException : Exception
{
internal RequestRetryType AllowRetry { get; } = RequestRetryType.NoRetry;
public HttpRequestException()
{ }
public HttpRequestException(string? message)
: base(message)
{ }
public HttpRequestException(string? message, Exception? inner)
: base(message, inner)
{
if (inner != null)
{
HResult = inner.HResult;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="HttpRequestException" /> class with a specific message that describes the current exception, an inner exception, and an HTTP status code.
/// </summary>
/// <param name="message">A message that describes the current exception.</param>
/// <param name="inner">The inner exception.</param>
/// <param name="statusCode">The HTTP status code.</param>
public HttpRequestException(string? message, Exception? inner, HttpStatusCode? statusCode)
: this(message, inner)
{
StatusCode = statusCode;
}
/// <summary>
/// Initializes a new instance of the <see cref="HttpRequestException" /> class with a specific message an inner exception, and an HTTP status code and an <see cref="HttpRequestError"/>.
/// </summary>
/// <param name="httpRequestError">The <see cref="HttpRequestError"/> that caused the exception.</param>
/// <param name="message">A message that describes the current exception.</param>
/// <param name="inner">The inner exception.</param>
/// <param name="statusCode">The HTTP status code.</param>
public HttpRequestException(HttpRequestError httpRequestError, string? message = null, Exception? inner = null, HttpStatusCode? statusCode = null)
: this(message, inner, statusCode)
{
HttpRequestError = httpRequestError;
}
/// <summary>
/// Gets the <see cref="Http.HttpRequestError"/> that caused the exception.
/// </summary>
public HttpRequestError HttpRequestError { get; }
/// <summary>
/// Gets the HTTP status code to be returned with the exception.
/// </summary>
/// <value>
/// An HTTP status code if the exception represents a non-successful result, otherwise <c>null</c>.
/// </value>
public HttpStatusCode? StatusCode { get; }
// This constructor is used internally to indicate that a request was not successfully sent due to an IOException,
// and the exception occurred early enough so that the request may be retried on another connection.
internal HttpRequestException(HttpRequestError httpRequestError, string? message, Exception? inner, RequestRetryType allowRetry)
: this(httpRequestError, message, inner)
{
AllowRetry = allowRetry;
}
}
}