From 481176470d5cf940d20b27afc2c98c7ee04afa86 Mon Sep 17 00:00:00 2001 From: Jeroen Maes Date: Thu, 8 May 2025 14:16:52 +0200 Subject: [PATCH] Update ProductApi.cs Warn, don't fail, when an API is not found when publishing an API product --- tools/code/publisher/ProductApi.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/code/publisher/ProductApi.cs b/tools/code/publisher/ProductApi.cs index 0c2527f6..a655ab05 100644 --- a/tools/code/publisher/ProductApi.cs +++ b/tools/code/publisher/ProductApi.cs @@ -9,6 +9,7 @@ using System.Diagnostics; using System.IO; using System.Linq; +using System.Net.Http; using System.Threading; using System.Threading.Tasks; @@ -164,8 +165,13 @@ private static PutProductApiInApim GetPutProductApiInApim(IServiceProvider provi { logger.LogInformation("Adding API {ApiName} to product {ProductName}...", name, productName); - await ProductApiUri.From(name, productName, serviceUri) - .PutDto(dto, pipeline, cancellationToken); + try { + await ProductApiUri.From(name, productName, serviceUri) + .PutDto(dto, pipeline, cancellationToken); + } catch (HttpRequestException httpRequestException) when (httpRequestException.Message.Contains("API not found", StringComparison.OrdinalIgnoreCase)){ + logger.LogWarning("API {ApiName} not found, the API is NOT added to product in the target environment.", name); + return; + } }; } @@ -246,4 +252,4 @@ await ProductApiUri.From(name, productName, serviceUri) .Delete(pipeline, cancellationToken); }; } -} \ No newline at end of file +}