Skip to content

Commit

Permalink
fix: Do not return empty papers/contacts if only one paper/contact
Browse files Browse the repository at this point in the history
conversion fail

Previously, when converting papers or contacts to ciphers, we were
returning an empty array when an error occured. So with 1000
contacts, if one conversion failed, we were seeing 0 contact.

Now we will see the 999 contacts that were successfully converted and
we will log an error for each paper or contact that failed to be
converted.
  • Loading branch information
zatteo committed Apr 20, 2024
1 parent b1a4201 commit 8407119
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 deletions.
20 changes: 12 additions & 8 deletions libs/cozy/contactCipher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ const convertContactsAsCiphers = async (
const key = await cryptoService.getKeyForUserEncryption();

for (const contact of contacts) {
const cipherResponse = await convertContactToCipherResponse(
cipherService,
i18nService,
contact,
key
);

contactsCiphers.push(cipherResponse);
try {
const cipherResponse = await convertContactToCipherResponse(
cipherService,
i18nService,
contact,
key
);

contactsCiphers.push(cipherResponse);
} catch (e) {
console.log(`Error during conversion of contact ${contact.id}`, contact, e);
}
}

return contactsCiphers;
Expand Down
47 changes: 26 additions & 21 deletions libs/cozy/paperCipher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,33 @@ export const convertPapersAsCiphers = async (

for (const paper of papers) {
let cipherResponse: CipherResponse;
if (isNote(paper)) {
cipherResponse = await convertNoteToCipherResponse(
cipherService,
i18nService,
paper,
{
noteIllustrationUrl,
},
key
);
} else {
cipherResponse = await convertPaperToCipherResponse(
cipherService,
i18nService,
paper,
{
baseUrl,
},
key
);
try {
if (isNote(paper)) {
cipherResponse = await convertNoteToCipherResponse(
cipherService,
i18nService,
paper,
{
noteIllustrationUrl,
},
key
);
} else {
cipherResponse = await convertPaperToCipherResponse(
cipherService,
i18nService,
paper,
{
baseUrl,
},
key
);
}

papersCiphers.push(cipherResponse);
} catch (e) {
console.log(`Error during conversion of paper ${paper.id}`, paper, e);
}
papersCiphers.push(cipherResponse);
}

return papersCiphers;
Expand Down

0 comments on commit 8407119

Please sign in to comment.