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.