Skip to content

Commit

Permalink
[Cancel] Cancelling a request on iOS now throw the inner TaskCanceled…
Browse files Browse the repository at this point in the history
…Exception instead of TimeoutException
  • Loading branch information
JeremyBP committed Oct 12, 2023
1 parent 5bb9418 commit 7330d99
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
7 changes: 6 additions & 1 deletion Apizr/Src/Apizr/ApizrHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ public override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage req
{
return await base.SendAsync(request, cts?.Token ?? cancellationToken).ConfigureAwait(false);
}
catch (TimeoutException ex)
when(ex.InnerException is OperationCanceledException cancelEx) // Actually a user cancellation (iOS)
{
throw cancelEx;
}
catch (WebException ex)
when (optionsCancellationToken.IsCancellationRequested) // Actually a user cancellation
when (optionsCancellationToken.IsCancellationRequested) // Actually a user cancellation (Android)
{
throw new OperationCanceledException(ex.Message, ex);
}
Expand Down
7 changes: 6 additions & 1 deletion Apizr/Src/Apizr/ApizrHttpMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
{
return await base.SendAsync(request, cts?.Token ?? cancellationToken).ConfigureAwait(false);
}
catch (TimeoutException ex)
when (ex.InnerException is OperationCanceledException cancelEx) // Actually a user cancellation (iOS)
{
throw cancelEx;
}
catch (WebException ex)
when (optionsCancellationToken.IsCancellationRequested) // Actually a user cancellation
when (optionsCancellationToken.IsCancellationRequested) // Actually a user cancellation (Android)
{
throw new OperationCanceledException(ex.Message, ex);
}
Expand Down
5 changes: 5 additions & 0 deletions Apizr/Tests/Apizr.Tests.Maui/Apizr.Tests.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='net7.0-ios'">
<CodesignKey>Apple Development: Jerome Liger (PPVW2MK6ZH)</CodesignKey>
<CodesignProvision>VS: WildCard Development</CodesignProvision>
</PropertyGroup>

<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
Expand Down
2 changes: 1 addition & 1 deletion Apizr/Tests/Apizr.Tests/Apis/IReqResResourceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//[assembly:Log]
namespace Apizr.Tests.Apis
{
[WebApi, Log(HttpMessageParts.None)]
[WebApi("https://reqres.in/api"), Log(HttpMessageParts.None)]
public interface IReqResResourceService
{
[Get("/unknown")]
Expand Down
2 changes: 1 addition & 1 deletion Apizr/Tests/Apizr.Tests/ApizrTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ public async Task Cancelling_A_Get_Request_Should_Throw_An_OperationCanceledExce
ex.WithInnerException<OperationCanceledException>();
}

[Fact]
[Fact] // todo: iOS fix => TimeoutException
public async Task Cancelling_A_Post_Request_Should_Throw_An_OperationCanceledException()
{
var manager = ApizrBuilder.Current.CreateManagerFor<IHttpBinService>();
Expand Down

0 comments on commit 7330d99

Please sign in to comment.