From 17105662e8a3dc01c89b51b17a64df147d3d16ac Mon Sep 17 00:00:00 2001 From: guythetechie <31325620+guythetechie@users.noreply.github.com> Date: Mon, 11 Mar 2024 14:04:27 +0000 Subject: [PATCH] Only catch open product error message --- tools/code/publisher/ProductApi.cs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/tools/code/publisher/ProductApi.cs b/tools/code/publisher/ProductApi.cs index 246c3041..df101056 100644 --- a/tools/code/publisher/ProductApi.cs +++ b/tools/code/publisher/ProductApi.cs @@ -163,23 +163,20 @@ private static async ValueTask Put(ApiName apiName, ProductUri productUri, PutRe await putRestResource(productApiUri.Uri, new JsonObject(), cancellationToken); retry = false; // No exception occurred, so no need to retry } - catch (HttpRequestException httpRequestException) + catch (HttpRequestException httpRequestException) when (httpRequestException.Message.Contains("API cannot be added to more than one open products")) { - if (httpRequestException.Message.Contains("API cannot be added to more than one open products")) + retryCount++; + if (retryCount <= 3) { - retryCount++; - if (retryCount <= 3) - { - // Log the retry attempt - logger.LogWarning("Retrying API put operation for {apiName}. Retry attempt: {retryCount}", apiName, retryCount); - // Wait for a certain duration before retrying - await Task.Delay(TimeSpan.FromSeconds(Math.Pow(2, retryCount)), cancellationToken); - } - else - { - // Retry limit reached, throw the exception - throw; - } + // Log the retry attempt + logger.LogWarning("Retrying API put operation for {apiName}. Retry attempt: {retryCount}", apiName, retryCount); + // Wait for a certain duration before retrying + await Task.Delay(TimeSpan.FromSeconds(Math.Pow(2, retryCount)), cancellationToken); + } + else + { + // Retry limit reached, throw the exception + throw; } } }