Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions ClientProxyBase/ClientProxyBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected virtual async Task<String> HandleResponse(HttpResponseMessage response
String result = String.Empty;

// Read the content from the response
String content = await responseMessage.Content.ReadAsStringAsync();
String content = await responseMessage.Content.ReadAsStringAsync(cancellationToken);

// Check the response code
if (!responseMessage.IsSuccessStatusCode)
Expand Down Expand Up @@ -87,14 +87,12 @@ protected virtual async Task<String> HandleResponse(HttpResponseMessage response
/// <exception cref="Exception">An internal error has occurred
/// or
/// An internal error has occurred</exception>
protected virtual async Task<Result<String>> HandleResponseX(HttpResponseMessage responseMessage,
CancellationToken cancellationToken)
protected virtual async Task<Result<StringResult>> HandleResponseX(HttpResponseMessage responseMessage,
CancellationToken cancellationToken)
{
String result = String.Empty;


// Read the content from the response
// Cant passs cancellation token as net standard does not support this :|
String content = await responseMessage.Content.ReadAsStringAsync();
String content = await responseMessage.Content.ReadAsStringAsync(cancellationToken);

// Check the response code
if (!responseMessage.IsSuccessStatusCode) {
Expand All @@ -108,13 +106,12 @@ protected virtual async Task<Result<String>> HandleResponseX(HttpResponseMessage
_ => Result.Failure($"An internal error has occurred ({responseMessage.StatusCode})")
};
}

// Set the result
result = content;

return result;

return Result.Success(new StringResult(content));
}

#endregion
}

public record StringResult(String StringData);
}
2 changes: 1 addition & 1 deletion ClientProxyBase/ClientProxyBase.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions Shared.Tests/ClientProxyBaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public async Task ClientProxyBase_HandleResponse_SuccessStatus(HttpStatusCode st
HttpResponseMessage response = new HttpResponseMessage(statusCode);
response.Content = new StringContent(responseContent);
TestClient proxybase = new TestClient(new HttpClient());
Result<String> result = await proxybase.Test(response, CancellationToken.None);
Result<StringResult> result = await proxybase.Test(response, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
result.Data.ShouldBe(responseContent);
result.Data.StringData.ShouldBe(responseContent);

}

Expand Down Expand Up @@ -131,7 +131,7 @@ public class TestClient : ClientProxyBase{
public TestClient(HttpClient httpClient) : base(httpClient){
}

public async Task<Result<String>> Test(HttpResponseMessage responseMessage, CancellationToken cancellationToken){
public async Task<Result<StringResult>> Test(HttpResponseMessage responseMessage, CancellationToken cancellationToken){
return await this.HandleResponseX(responseMessage, cancellationToken);
}
}
Expand Down