From b9e78fa4347871a643b7176678334dbb827a0214 Mon Sep 17 00:00:00 2001 From: westwok Date: Tue, 19 Jan 2016 22:40:37 +0000 Subject: [PATCH 1/2] Changed GetRawResponseContent to return content if there is some regardless of HttpStatusCode --- src/PortableRest/RestClient.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/PortableRest/RestClient.cs b/src/PortableRest/RestClient.cs index 5120686..b53ee3d 100644 --- a/src/PortableRest/RestClient.cs +++ b/src/PortableRest/RestClient.cs @@ -433,10 +433,11 @@ private static async Task GetResponseContent([NotNull] RestRequest restReq /// private static async Task GetRawResponseContent([NotNull] HttpResponseMessage response) { - //RWM: Explicitly check for NoContent... because the request was successful but there is nothing to do. - if (response.IsSuccessStatusCode && response.StatusCode != HttpStatusCode.NoContent) + //KW: If there's content I want to know what it is regardless of the wether the response has a success code + if (response.StatusCode != HttpStatusCode.NoContent) { - return await response.Content.ReadAsStringAsync().ConfigureAwait(false); + string stringContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + return string.IsNullOrEmpty(stringContent) ? null : stringContent; } return null; } From 8991639cb042a4d74ba17d43f0b27676c6040c14 Mon Sep 17 00:00:00 2001 From: westwok Date: Wed, 27 Jan 2016 20:23:34 +0000 Subject: [PATCH 2/2] Return more information to the developer when there's a JsonSerializationException. If it was a 404 you would not know otherwise. --- src/PortableRest/RestClient.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/PortableRest/RestClient.cs b/src/PortableRest/RestClient.cs index b53ee3d..207a23e 100644 --- a/src/PortableRest/RestClient.cs +++ b/src/PortableRest/RestClient.cs @@ -469,7 +469,10 @@ private static T DeserializeResponseContent([NotNull] RestRequest restRequest } catch (JsonSerializationException jEx) { - throw new PortableRestException("The JsonConverter failed. Please see InnerException for details.", jEx); + var prEx = new PortableRestException( + "The JsonConverter failed. Please see InnerException " + + $"for details. StatusCode {response.StatusCode} : ReasonPhrase {response.ReasonPhrase}", jEx); + throw prEx; } }