| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | namespace System.Net.Http |
| | | 5 | | { |
| | | 6 | | public class HttpRequestException : Exception |
| | | 7 | | { |
| | 0 | 8 | | internal RequestRetryType AllowRetry { get; } = RequestRetryType.NoRetry; |
| | | 9 | | |
| | 0 | 10 | | public HttpRequestException() |
| | 0 | 11 | | { } |
| | | 12 | | |
| | | 13 | | public HttpRequestException(string? message) |
| | 0 | 14 | | : base(message) |
| | 0 | 15 | | { } |
| | | 16 | | |
| | | 17 | | public HttpRequestException(string? message, Exception? inner) |
| | 0 | 18 | | : base(message, inner) |
| | 0 | 19 | | { |
| | 0 | 20 | | if (inner != null) |
| | 0 | 21 | | { |
| | 0 | 22 | | HResult = inner.HResult; |
| | 0 | 23 | | } |
| | 0 | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Initializes a new instance of the <see cref="HttpRequestException" /> class with a specific message that des |
| | | 28 | | /// </summary> |
| | | 29 | | /// <param name="message">A message that describes the current exception.</param> |
| | | 30 | | /// <param name="inner">The inner exception.</param> |
| | | 31 | | /// <param name="statusCode">The HTTP status code.</param> |
| | | 32 | | public HttpRequestException(string? message, Exception? inner, HttpStatusCode? statusCode) |
| | 0 | 33 | | : this(message, inner) |
| | 0 | 34 | | { |
| | 0 | 35 | | StatusCode = statusCode; |
| | 0 | 36 | | } |
| | | 37 | | |
| | | 38 | | /// <summary> |
| | | 39 | | /// Initializes a new instance of the <see cref="HttpRequestException" /> class with a specific message an inner |
| | | 40 | | /// </summary> |
| | | 41 | | /// <param name="httpRequestError">The <see cref="HttpRequestError"/> that caused the exception.</param> |
| | | 42 | | /// <param name="message">A message that describes the current exception.</param> |
| | | 43 | | /// <param name="inner">The inner exception.</param> |
| | | 44 | | /// <param name="statusCode">The HTTP status code.</param> |
| | | 45 | | public HttpRequestException(HttpRequestError httpRequestError, string? message = null, Exception? inner = null, |
| | 0 | 46 | | : this(message, inner, statusCode) |
| | 0 | 47 | | { |
| | 0 | 48 | | HttpRequestError = httpRequestError; |
| | 0 | 49 | | } |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Gets the <see cref="Http.HttpRequestError"/> that caused the exception. |
| | | 53 | | /// </summary> |
| | 0 | 54 | | public HttpRequestError HttpRequestError { get; } |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Gets the HTTP status code to be returned with the exception. |
| | | 58 | | /// </summary> |
| | | 59 | | /// <value> |
| | | 60 | | /// An HTTP status code if the exception represents a non-successful result, otherwise <c>null</c>. |
| | | 61 | | /// </value> |
| | 0 | 62 | | public HttpStatusCode? StatusCode { get; } |
| | | 63 | | |
| | | 64 | | // This constructor is used internally to indicate that a request was not successfully sent due to an IOExceptio |
| | | 65 | | // and the exception occurred early enough so that the request may be retried on another connection. |
| | | 66 | | internal HttpRequestException(HttpRequestError httpRequestError, string? message, Exception? inner, RequestRetry |
| | 0 | 67 | | : this(httpRequestError, message, inner) |
| | 0 | 68 | | { |
| | 0 | 69 | | AllowRetry = allowRetry; |
| | 0 | 70 | | } |
| | | 71 | | } |
| | | 72 | | } |