Skip to content

Commit

Permalink
Merge pull request #500 from Azure/495-bug-http-exception-not-handled…
Browse files Browse the repository at this point in the history
…-endless-loop-when-putting-api-in-product

Only catch open product error message
  • Loading branch information
guythetechie authored Mar 12, 2024
2 parents 156314f + 1710566 commit 2aa87ea
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions tools/code/publisher/ProductApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down

0 comments on commit 2aa87ea

Please sign in to comment.