From 0534090d03308ebadc5bb4d0322fc60c9defc4e3 Mon Sep 17 00:00:00 2001 From: Adrian Hall Date: Mon, 28 Jul 2025 09:53:01 -0700 Subject: [PATCH] (#397) Allow 404/410 to mean success on push deletes --- .../Offline/Operations/DeleteOperation.cs | 13 ++++++++++++- .../Service/ServiceResponse.cs | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/CommunityToolkit.Datasync.Client/Offline/Operations/DeleteOperation.cs b/src/CommunityToolkit.Datasync.Client/Offline/Operations/DeleteOperation.cs index b7b48c1d..9149dfc1 100644 --- a/src/CommunityToolkit.Datasync.Client/Offline/Operations/DeleteOperation.cs +++ b/src/CommunityToolkit.Datasync.Client/Offline/Operations/DeleteOperation.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using CommunityToolkit.Datasync.Client.Offline.Models; +using System.Net; using System.Net.Http.Headers; namespace CommunityToolkit.Datasync.Client.Offline.Operations; @@ -29,6 +30,16 @@ internal override async Task ExecuteAsync(EntityDatasyncOptions } using HttpResponseMessage response = await options.HttpClient.SendAsync(request, cancellationToken).ConfigureAwait(false); - return new ServiceResponse(response); + ServiceResponse serviceResponse = new(response); + + // #397 - if the response is 404 (Not Found) or 410 (Gone), we return a successful response + // since the item was deleted on the server. + if (response.StatusCode is HttpStatusCode.NotFound or HttpStatusCode.Gone) + { + // Convert the response to a successful response + serviceResponse.StatusCode = (int)HttpStatusCode.NoContent; + } + + return serviceResponse; } } diff --git a/src/CommunityToolkit.Datasync.Client/Service/ServiceResponse.cs b/src/CommunityToolkit.Datasync.Client/Service/ServiceResponse.cs index eb118630..e95fb8b3 100644 --- a/src/CommunityToolkit.Datasync.Client/Service/ServiceResponse.cs +++ b/src/CommunityToolkit.Datasync.Client/Service/ServiceResponse.cs @@ -84,7 +84,7 @@ internal ServiceResponse(ServiceResponse response) /// /// The HTTP status code for this response. /// - public int StatusCode { get; } + public int StatusCode { get; internal set; } /// /// Tries to get a header returned by the response; returns true if the header exists and false otherwise.