diff --git a/src/RestClient/RestClient/src/Error.cs b/src/RestClient/RestClient/src/Error.cs index efd461f..0317a7a 100644 --- a/src/RestClient/RestClient/src/Error.cs +++ b/src/RestClient/RestClient/src/Error.cs @@ -11,6 +11,7 @@ public Error(HttpStatusCode httpStatusCode, ErrorBody body) } public HttpStatusCode HttpStatusCode { get; } + public string Content { get; set; } public ErrorBody Body { get; } } } diff --git a/src/RestClient/RestClient/src/Requests/BaseRestClientRequest.cs b/src/RestClient/RestClient/src/Requests/BaseRestClientRequest.cs index d97d686..a0f036d 100644 --- a/src/RestClient/RestClient/src/Requests/BaseRestClientRequest.cs +++ b/src/RestClient/RestClient/src/Requests/BaseRestClientRequest.cs @@ -151,15 +151,15 @@ protected async Task GetErrorAsync(HttpResponseMessage message) if (message.IsSuccessStatusCode) return null; - if (message.Content != null) - { - var content = await message.Content.ReadAsStringAsync().ConfigureAwait(false); + var contentString = await message.Content.ReadAsStringAsync().ConfigureAwait(false); - if (TryParseErrorBody(content, out var errorBody)) - return new Error(message.StatusCode, errorBody); - } + if (!TryParseErrorBody(contentString, out var errorBody)) + errorBody = GetDefaultErrorBody(message.StatusCode, message.ReasonPhrase); - return new Error(message.StatusCode, GetDefaultErrorBody(message.StatusCode, message.ReasonPhrase)); + return new Error(message.StatusCode, errorBody) + { + Content = contentString + }; } protected virtual void HandleError(Error error)