From 8f5f694a1ea5dbbc9501b270b10559bbbfd107c1 Mon Sep 17 00:00:00 2001 From: Robyn MacCallum Date: Wed, 2 Mar 2022 08:11:34 -0500 Subject: [PATCH] Roll back organizationId and collectionId's if ciphers fail to be moved (#699) --- common/src/services/cipher.service.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/common/src/services/cipher.service.ts b/common/src/services/cipher.service.ts index 91cfb464e9..ec98c34763 100644 --- a/common/src/services/cipher.service.ts +++ b/common/src/services/cipher.service.ts @@ -657,7 +657,15 @@ export class CipherService implements CipherServiceAbstraction { } await Promise.all(promises); const request = new CipherBulkShareRequest(encCiphers, collectionIds); - await this.apiService.putShareCiphers(request); + try { + await this.apiService.putShareCiphers(request); + } catch (e) { + for (const cipher of ciphers) { + cipher.organizationId = null; + cipher.collectionIds = null; + } + throw e; + } const userId = await this.stateService.getUserId(); await this.upsert(encCiphers.map((c) => c.toCipherData(userId))); }