Skip to content

Commit

Permalink
error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
michelle0927 committed Oct 16, 2024
1 parent dd0bef4 commit 2cd225d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/gmail/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/gmail",
"version": "0.1.8",
"version": "0.1.9",
"description": "Pipedream Gmail Components",
"main": "gmail.app.mjs",
"keywords": [
Expand Down
24 changes: 21 additions & 3 deletions components/gmail/sources/new-email-received/new-email-received.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default {
name: "New Email Received",
description: "Emit new event when a new email is received.",
type: "source",
version: "0.1.5",
version: "0.1.6",
dedupe: "unique",
props: {
gmail,
Expand Down Expand Up @@ -383,6 +383,20 @@ export default {
)
: history.filter((item) => item.messagesAdded?.length);
},
async getMessageDetails(ids) {
const messages = await Promise.all(ids.map(async (id) => {
try {
const message = await this.gmail.getMessage({
id,
});
return message;
} catch {
console.log(`Could not find message ${id}`);
return null;
}
}));
return messages;
},
},
async run(event) {
if (this.triggerType === "polling") {
Expand Down Expand Up @@ -464,7 +478,7 @@ export default {

// Fetch full message details for new messages
const newMessageIds = newMessages?.map(({ id }) => id) || [];
const messageDetails = await this.gmail.getMessages(newMessageIds);
const messageDetails = await this.getMessageDetails(newMessageIds);

if (!messageDetails?.length) {
return;
Expand All @@ -477,7 +491,11 @@ export default {
this._setLastProcessedHistoryId(latestHistoryId);
console.log("Updated lastProcessedHistoryId:", latestHistoryId);

messageDetails.forEach((message) => this.emitEvent(message));
messageDetails.forEach((message) => {
if (message?.id) {
this.emitEvent(message);
}
});
}
},
};

0 comments on commit 2cd225d

Please sign in to comment.