Skip to content

Commit

Permalink
#557: handle key-not-found during retrieve and show key after downloa…
Browse files Browse the repository at this point in the history
…d-count for transactionalEmail
  • Loading branch information
JoernBerkefeld committed Nov 23, 2022
1 parent 563728b commit 3a2cfcc
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lib/metadataTypes/TransactionalEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,29 @@ class TransactionalEmail extends MetadataType {
}

// get all sms with additional details not given by the list endpoint
const details = keyList
? await Promise.all(keyList.map((key) => this.client.rest.get(baseUri + (key || ''))))
: [];

const details = (
await Promise.all(
keyList.map(async (key) => {
try {
return await this.client.rest.get(baseUri + (key || ''));
} catch {
return null;
}
})
)
).filter(Boolean);
const parsed = this.parseResponseBody({ definitions: details });

// * retrieveDir is mandatory in this method as it is not used for caching (there is a seperate method for that)
const savedMetadata = await this.saveResults(parsed, retrieveDir, null, null);
// defined colors for optionally printing the keys we filtered by
const color = {
reset: '\x1B[0m',
dim: '\x1B[2m',
};
Util.logger.info(
`Downloaded: ${this.definition.type} (${Object.keys(savedMetadata).length})`
`Downloaded: ${this.definition.type} (${Object.keys(savedMetadata).length})` +
(key !== null ? ` ${color.dim}(Key: ${key})${color.reset}` : '')
);

return { metadata: savedMetadata, type: this.definition.type };
Expand Down

0 comments on commit 3a2cfcc

Please sign in to comment.