Skip to content

Commit de8292f

Browse files
adrianhallAdrian Hall
andauthored
(#397) Allow 404/410 to mean success on push deletes (#399)
Co-authored-by: Adrian Hall <[email protected]>
1 parent 0511bb1 commit de8292f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/CommunityToolkit.Datasync.Client/Offline/Operations/DeleteOperation.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using CommunityToolkit.Datasync.Client.Offline.Models;
6+
using System.Net;
67
using System.Net.Http.Headers;
78

89
namespace CommunityToolkit.Datasync.Client.Offline.Operations;
@@ -29,6 +30,16 @@ internal override async Task<ServiceResponse> ExecuteAsync(EntityDatasyncOptions
2930
}
3031

3132
using HttpResponseMessage response = await options.HttpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);
32-
return new ServiceResponse(response);
33+
ServiceResponse serviceResponse = new(response);
34+
35+
// #397 - if the response is 404 (Not Found) or 410 (Gone), we return a successful response
36+
// since the item was deleted on the server.
37+
if (response.StatusCode is HttpStatusCode.NotFound or HttpStatusCode.Gone)
38+
{
39+
// Convert the response to a successful response
40+
serviceResponse.StatusCode = (int)HttpStatusCode.NoContent;
41+
}
42+
43+
return serviceResponse;
3344
}
3445
}

src/CommunityToolkit.Datasync.Client/Service/ServiceResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ internal ServiceResponse(ServiceResponse response)
8484
/// <summary>
8585
/// The HTTP status code for this response.
8686
/// </summary>
87-
public int StatusCode { get; }
87+
public int StatusCode { get; internal set; }
8888

8989
/// <summary>
9090
/// Tries to get a header returned by the response; returns true if the header exists and false otherwise.

0 commit comments

Comments
 (0)