diff --git a/.github/ISSUE_TEMPLATE/Bug_report.yml b/.github/ISSUE_TEMPLATE/Bug_report.yml index ecf2dfdbd..d01e1b390 100644 --- a/.github/ISSUE_TEMPLATE/Bug_report.yml +++ b/.github/ISSUE_TEMPLATE/Bug_report.yml @@ -27,7 +27,7 @@ body: id: client attributes: label: Client - description: Which API are you targetting? + description: Which API are you targeting? options: - All - AB testing diff --git a/algoliasearch/Utils/SearchClientExtensions.cs b/algoliasearch/Utils/SearchClientExtensions.cs index 038c7d60a..bdd5f41b3 100644 --- a/algoliasearch/Utils/SearchClientExtensions.cs +++ b/algoliasearch/Utils/SearchClientExtensions.cs @@ -494,37 +494,46 @@ public async Task ReplaceAllObjectsAsync(string in var rnd = new Random(); var tmpIndexName = $"{indexName}_tmp_{rnd.Next(100)}"; - var copyResponse = await OperationIndexAsync(indexName, - new OperationIndexParams(OperationType.Copy, tmpIndexName) - { Scope = [ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms] }, options, cancellationToken) - .ConfigureAwait(false); + try + { + var copyResponse = await OperationIndexAsync(indexName, + new OperationIndexParams(OperationType.Copy, tmpIndexName) + { Scope = [ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms] }, options, cancellationToken) + .ConfigureAwait(false); - var batchResponse = await ChunkedBatchAsync(tmpIndexName, objects, Action.AddObject, true, batchSize, - options, cancellationToken).ConfigureAwait(false); + var batchResponse = await ChunkedBatchAsync(tmpIndexName, objects, Action.AddObject, true, batchSize, + options, cancellationToken).ConfigureAwait(false); - await WaitForTaskAsync(tmpIndexName, copyResponse.TaskID, requestOptions: options, ct: cancellationToken) - .ConfigureAwait(false); + await WaitForTaskAsync(tmpIndexName, copyResponse.TaskID, requestOptions: options, ct: cancellationToken) + .ConfigureAwait(false); - copyResponse = await OperationIndexAsync(indexName, - new OperationIndexParams(OperationType.Copy, tmpIndexName) - { Scope = [ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms] }, options, cancellationToken) - .ConfigureAwait(false); - await WaitForTaskAsync(tmpIndexName, copyResponse.TaskID, requestOptions: options, ct: cancellationToken) - .ConfigureAwait(false); + copyResponse = await OperationIndexAsync(indexName, + new OperationIndexParams(OperationType.Copy, tmpIndexName) + { Scope = [ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms] }, options, cancellationToken) + .ConfigureAwait(false); + await WaitForTaskAsync(tmpIndexName, copyResponse.TaskID, requestOptions: options, ct: cancellationToken) + .ConfigureAwait(false); - var moveResponse = await OperationIndexAsync(tmpIndexName, - new OperationIndexParams(OperationType.Move, indexName), options, cancellationToken) - .ConfigureAwait(false); + var moveResponse = await OperationIndexAsync(tmpIndexName, + new OperationIndexParams(OperationType.Move, indexName), options, cancellationToken) + .ConfigureAwait(false); - await WaitForTaskAsync(tmpIndexName, moveResponse.TaskID, requestOptions: options, ct: cancellationToken) - .ConfigureAwait(false); + await WaitForTaskAsync(tmpIndexName, moveResponse.TaskID, requestOptions: options, ct: cancellationToken) + .ConfigureAwait(false); - return new ReplaceAllObjectsResponse + return new ReplaceAllObjectsResponse + { + CopyOperationResponse = copyResponse, + MoveOperationResponse = moveResponse, + BatchResponses = batchResponse + }; + } + catch (Exception ex) { - CopyOperationResponse = copyResponse, - MoveOperationResponse = moveResponse, - BatchResponses = batchResponse - }; + await DeleteIndexAsync(tmpIndexName, cancellationToken: cancellationToken).ConfigureAwait(false); + + throw ex; + } } ///