Skip to content

Commit 93eb697

Browse files
algolia-botmillotpFluf22
committed
feat(clients): cleanup after replaceAllObjects failure [skip-bc] (generated)
algolia/api-clients-automation#3824 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Pierre Millot <[email protected]> Co-authored-by: Thomas Raffray <[email protected]>
1 parent 7e0027e commit 93eb697

File tree

2 files changed

+50
-44
lines changed

2 files changed

+50
-44
lines changed

.github/ISSUE_TEMPLATE/Bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ body:
2727
id: client
2828
attributes:
2929
label: Client
30-
description: Which API are you targetting?
30+
description: Which API are you targeting?
3131
options:
3232
- All
3333
- AB testing

packages/client-search/src/searchClient.ts

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -642,57 +642,63 @@ export function createSearchClient({
642642
const randomSuffix = Math.floor(Math.random() * 1000000) + 100000;
643643
const tmpIndexName = `${indexName}_tmp_${randomSuffix}`;
644644

645-
let copyOperationResponse = await this.operationIndex(
646-
{
647-
indexName,
648-
operationIndexParams: {
649-
operation: 'copy',
650-
destination: tmpIndexName,
651-
scope: ['settings', 'rules', 'synonyms'],
645+
try {
646+
let copyOperationResponse = await this.operationIndex(
647+
{
648+
indexName,
649+
operationIndexParams: {
650+
operation: 'copy',
651+
destination: tmpIndexName,
652+
scope: ['settings', 'rules', 'synonyms'],
653+
},
652654
},
653-
},
654-
requestOptions,
655-
);
655+
requestOptions,
656+
);
656657

657-
const batchResponses = await this.chunkedBatch(
658-
{ indexName: tmpIndexName, objects, waitForTasks: true, batchSize },
659-
requestOptions,
660-
);
658+
const batchResponses = await this.chunkedBatch(
659+
{ indexName: tmpIndexName, objects, waitForTasks: true, batchSize },
660+
requestOptions,
661+
);
661662

662-
await this.waitForTask({
663-
indexName: tmpIndexName,
664-
taskID: copyOperationResponse.taskID,
665-
});
663+
await this.waitForTask({
664+
indexName: tmpIndexName,
665+
taskID: copyOperationResponse.taskID,
666+
});
666667

667-
copyOperationResponse = await this.operationIndex(
668-
{
669-
indexName,
670-
operationIndexParams: {
671-
operation: 'copy',
672-
destination: tmpIndexName,
673-
scope: ['settings', 'rules', 'synonyms'],
668+
copyOperationResponse = await this.operationIndex(
669+
{
670+
indexName,
671+
operationIndexParams: {
672+
operation: 'copy',
673+
destination: tmpIndexName,
674+
scope: ['settings', 'rules', 'synonyms'],
675+
},
674676
},
675-
},
676-
requestOptions,
677-
);
678-
await this.waitForTask({
679-
indexName: tmpIndexName,
680-
taskID: copyOperationResponse.taskID,
681-
});
677+
requestOptions,
678+
);
679+
await this.waitForTask({
680+
indexName: tmpIndexName,
681+
taskID: copyOperationResponse.taskID,
682+
});
682683

683-
const moveOperationResponse = await this.operationIndex(
684-
{
684+
const moveOperationResponse = await this.operationIndex(
685+
{
686+
indexName: tmpIndexName,
687+
operationIndexParams: { operation: 'move', destination: indexName },
688+
},
689+
requestOptions,
690+
);
691+
await this.waitForTask({
685692
indexName: tmpIndexName,
686-
operationIndexParams: { operation: 'move', destination: indexName },
687-
},
688-
requestOptions,
689-
);
690-
await this.waitForTask({
691-
indexName: tmpIndexName,
692-
taskID: moveOperationResponse.taskID,
693-
});
693+
taskID: moveOperationResponse.taskID,
694+
});
694695

695-
return { copyOperationResponse, batchResponses, moveOperationResponse };
696+
return { copyOperationResponse, batchResponses, moveOperationResponse };
697+
} catch (error) {
698+
await this.deleteIndex({ indexName: tmpIndexName });
699+
700+
throw error;
701+
}
696702
},
697703

698704
async indexExists({ indexName }: GetSettingsProps): Promise<boolean> {

0 commit comments

Comments
 (0)