Skip to content

Commit 2aa87ea

Browse files
authored
Merge pull request #500 from Azure/495-bug-http-exception-not-handled-endless-loop-when-putting-api-in-product
Only catch open product error message
2 parents 156314f + 1710566 commit 2aa87ea

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

tools/code/publisher/ProductApi.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,23 +163,20 @@ private static async ValueTask Put(ApiName apiName, ProductUri productUri, PutRe
163163
await putRestResource(productApiUri.Uri, new JsonObject(), cancellationToken);
164164
retry = false; // No exception occurred, so no need to retry
165165
}
166-
catch (HttpRequestException httpRequestException)
166+
catch (HttpRequestException httpRequestException) when (httpRequestException.Message.Contains("API cannot be added to more than one open products"))
167167
{
168-
if (httpRequestException.Message.Contains("API cannot be added to more than one open products"))
168+
retryCount++;
169+
if (retryCount <= 3)
169170
{
170-
retryCount++;
171-
if (retryCount <= 3)
172-
{
173-
// Log the retry attempt
174-
logger.LogWarning("Retrying API put operation for {apiName}. Retry attempt: {retryCount}", apiName, retryCount);
175-
// Wait for a certain duration before retrying
176-
await Task.Delay(TimeSpan.FromSeconds(Math.Pow(2, retryCount)), cancellationToken);
177-
}
178-
else
179-
{
180-
// Retry limit reached, throw the exception
181-
throw;
182-
}
171+
// Log the retry attempt
172+
logger.LogWarning("Retrying API put operation for {apiName}. Retry attempt: {retryCount}", apiName, retryCount);
173+
// Wait for a certain duration before retrying
174+
await Task.Delay(TimeSpan.FromSeconds(Math.Pow(2, retryCount)), cancellationToken);
175+
}
176+
else
177+
{
178+
// Retry limit reached, throw the exception
179+
throw;
183180
}
184181
}
185182
}

0 commit comments

Comments
 (0)