From 7bfbd80af2cf2079e14c529425dd31219ed5af2a Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 5 Mar 2026 20:38:34 +0100 Subject: [PATCH] fix: treat HTTP 404 on DELETE as success (idempotent delete) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the publisher tries to delete a resource that has already been removed from APIM (e.g. a manually deleted API revision), the DELETE call returns HTTP 404. Previously, DeleteResource threw an exception on any error response including 404, causing the entire publisher pipeline to crash. This change makes DeleteResource ignore 404 responses on DELETE, treating them as successful — the resource is already gone, which is the desired end state. This follows the REST convention of idempotent deletes and is consistent with how GetContentOption already handles 404 for GET requests. The fix applies to all resource types (ApiTag, Api, Backend, Logger, Diagnostic, etc.) since they all call DeleteResource. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tools/code/common/Http.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/code/common/Http.cs b/tools/code/common/Http.cs index 0fabf654..0131c0ee 100644 --- a/tools/code/common/Http.cs +++ b/tools/code/common/Http.cs @@ -128,7 +128,16 @@ public static async ValueTask DeleteResource(this HttpPipeline pipeline, Uri uri { var either = await pipeline.TryDeleteResource(uri, waitForCompletion, cancellationToken); - either.IfLeftThrow(uri); + either.IfLeft(response => + { + using (response) + { + if (response.Status != 404) + { + throw response.ToHttpRequestException(uri); + } + } + }); } public static async ValueTask> TryDeleteResource(this HttpPipeline pipeline, Uri uri, bool waitForCompletion, CancellationToken cancellationToken)