Skip to content

Commit 4fb5f4e

Browse files
author
o.nadymov
committed
Add ReasonPhrase into RestResponse and into exception header text.
1 parent 5022ca1 commit 4fb5f4e

File tree

6 files changed

+22
-9
lines changed

6 files changed

+22
-9
lines changed

src/Directory.Build.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
<PackageTags>RestClient; Rest; Rest-Client; Http; HttpClient</PackageTags>
3636
<Copyright>Copyright © $([System.DateTime]::Now.Year.ToString())</Copyright>
3737
<PackageReleaseNotes></PackageReleaseNotes>
38-
<Version>1.0.16</Version>
39-
<AssemblyVersion>1.0.16.0</AssemblyVersion>
40-
<FileVersion>1.0.16.0</FileVersion>
38+
<Version>1.0.17</Version>
39+
<AssemblyVersion>1.0.17.0</AssemblyVersion>
40+
<FileVersion>1.0.17.0</FileVersion>
4141
</PropertyGroup>
4242

4343
<PropertyGroup Condition="'$(Configuration)' == 'Release'">

src/Spoleto.RestClient/Client/RestHttpClient.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public async Task<BinaryRestResponse> ExecuteAsBytesAsync(RestRequest request, C
6262

6363
if (!restResponse.IsSuccessStatusCode)
6464
{
65-
throw new Exception($"Unsuccesful response with {nameof(restResponse.StatusCode)} = {restResponse.StatusCode}");
65+
throw new Exception($"Unsuccessful response with {nameof(restResponse.StatusCode)} = {restResponse.StatusCode}, {nameof(restResponse.ReasonPhrase)} = {restResponse.ReasonPhrase}");
6666
}
6767

6868

@@ -123,20 +123,22 @@ public async Task<BinaryRestResponse> ExecuteAsBytesAsync(RestRequest request, C
123123
errorResult = restResponse.Encoding.GetString(binaryRestResponse.Content);
124124
}
125125

126+
var errorText = $"{(int)responseMessage.StatusCode} {responseMessage.ReasonPhrase}";
127+
126128
if (!String.IsNullOrEmpty(errorResult))
127129
{
128-
//_logger.LogError(errorResult);
130+
//_logger.LogError($"{errorText}{Environment.NewLine}{errorResult}");
129131

130-
var exception = new Exception(errorResult);
132+
var exception = new Exception(errorText, new Exception(errorResult));
131133
exception.InitializeException(responseMessage);
132134

133135
throw exception;
134136
}
135137
else
136138
{
137-
//_logger.LogError(responseMessage.ReasonPhrase);
139+
//_logger.LogError(errorText);
138140

139-
var exception = new Exception(responseMessage.ReasonPhrase);
141+
var exception = new Exception(errorText);
140142
exception.InitializeException(responseMessage);
141143

142144
throw exception;

src/Spoleto.RestClient/Extensions/RestClientExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static class RestClientExtensions
2121

2222
if (!restResponse.IsSuccessStatusCode)
2323
{
24-
throw new Exception($"Unsuccesful response with {nameof(restResponse.StatusCode)} = {restResponse.StatusCode}");
24+
throw new Exception($"Unsuccessful response with {nameof(restResponse.StatusCode)} = {restResponse.StatusCode}, {nameof(restResponse.ReasonPhrase)} = {restResponse.ReasonPhrase}");
2525
}
2626

2727
if (string.IsNullOrEmpty(restResponse.Content))

src/Spoleto.RestClient/RestResponse/IRestResponse.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public interface IRestResponse
1515
/// </summary>
1616
HttpStatusCode StatusCode { get; set; }
1717

18+
/// <summary>
19+
/// Gets or sets the reason phrase which typically is sent by servers together with the status code.
20+
/// </summary>
21+
public string? ReasonPhrase { get; set; }
22+
1823
/// <summary>
1924
/// Gets or sets the value of the MediaType from Content-Type content header on an HTTP response.
2025
/// </summary>

src/Spoleto.RestClient/RestResponse/ResponseExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public static class ResponseExtensions
1010
{
1111
IsSuccessStatusCode = responseMessage.IsSuccessStatusCode,
1212
StatusCode = responseMessage.StatusCode,
13+
ReasonPhrase = responseMessage.ReasonPhrase,
1314
ContentType = responseMessage.Content?.Headers.ContentType?.MediaType
1415
};
1516

src/Spoleto.RestClient/RestResponse/RestResponse.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public RestResponse(TContent content)
2626
/// </summary>
2727
public HttpStatusCode StatusCode { get; set; }
2828

29+
/// <summary>
30+
/// Gets or sets the reason phrase which typically is sent by servers together with the status code.
31+
/// </summary>
32+
public string? ReasonPhrase { get; set; }
33+
2934
/// <summary>
3035
/// Gets or sets the value of the MediaType from Content-Type content header on an HTTP response.
3136
/// </summary>

0 commit comments

Comments
 (0)