This commit is contained in:
Oren Novotny 2018-01-28 12:50:46 -05:00
Родитель ac796f4fae
Коммит 0e3b7e5077
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: D501F3955648A88A
2 изменённых файлов: 17 добавлений и 13 удалений

Просмотреть файл

@ -9,11 +9,12 @@ namespace Refit
{
public class ApiException : Exception
{
public HttpStatusCode StatusCode { get; private set; }
public string ReasonPhrase { get; private set; }
public HttpResponseHeaders Headers { get; private set; }
public HttpMethod HttpMethod { get; private set; }
public Uri Uri { get; private set; }
public HttpStatusCode StatusCode { get; }
public string ReasonPhrase { get; }
public HttpResponseHeaders Headers { get; }
public HttpMethod HttpMethod { get; }
public Uri Uri => RequestMessage.RequestUri;
public HttpRequestMessage RequestMessage { get; }
public HttpContentHeaders ContentHeaders { get; private set; }
@ -22,10 +23,10 @@ namespace Refit
public bool HasContent => !string.IsNullOrWhiteSpace(Content);
public RefitSettings RefitSettings { get; set; }
ApiException(Uri uri, HttpMethod httpMethod, HttpStatusCode statusCode, string reasonPhrase, HttpResponseHeaders headers, RefitSettings refitSettings = null) :
ApiException(HttpRequestMessage message, HttpMethod httpMethod, HttpStatusCode statusCode, string reasonPhrase, HttpResponseHeaders headers, RefitSettings refitSettings = null) :
base(CreateMessage(statusCode, reasonPhrase))
{
Uri = uri;
RequestMessage = message;
HttpMethod = httpMethod;
StatusCode = statusCode;
ReasonPhrase = reasonPhrase;
@ -38,19 +39,22 @@ namespace Refit
default;
#pragma warning disable VSTHRD200 // Use "Async" suffix for async methods
public static async Task<ApiException> Create(Uri uri, HttpMethod httpMethod, HttpResponseMessage response, RefitSettings refitSettings = null)
public static async Task<ApiException> Create(HttpRequestMessage message, HttpMethod httpMethod, HttpResponseMessage response, RefitSettings refitSettings = null)
#pragma warning restore VSTHRD200 // Use "Async" suffix for async methods
{
var exception = new ApiException(uri, httpMethod, response.StatusCode, response.ReasonPhrase, response.Headers, refitSettings);
var exception = new ApiException(message, httpMethod, response.StatusCode, response.ReasonPhrase, response.Headers, refitSettings);
if (response.Content == null)
return exception;
try {
try
{
exception.ContentHeaders = response.Content.Headers;
exception.Content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
response.Content.Dispose();
} catch {
}
catch
{
// NB: We're already handling an exception at this point,
// so we want to make sure we don't throw another one
// that hides the real error.

Просмотреть файл

@ -204,7 +204,7 @@ namespace Refit
if (!resp.IsSuccessStatusCode)
{
disposeResponse = false;
throw await ApiException.Create(rq.RequestUri, restMethod.HttpMethod, resp, restMethod.RefitSettings).ConfigureAwait(false);
throw await ApiException.Create(rq, restMethod.HttpMethod, resp, restMethod.RefitSettings).ConfigureAwait(false);
}
if (restMethod.SerializedReturnType == typeof(HttpContent))
@ -601,7 +601,7 @@ namespace Refit
{
if (!resp.IsSuccessStatusCode)
{
throw await ApiException.Create(rq.RequestUri, restMethod.HttpMethod, resp, settings).ConfigureAwait(false);
throw await ApiException.Create(rq, restMethod.HttpMethod, resp, settings).ConfigureAwait(false);
}
}
};