Skip to content

Commit 3e09219

Browse files
fix: add retry logic to getEmailBody to handle mailsac eventual consistency (#5241)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: derek@reown.com <alexanderderekrein@gmail.com>
1 parent 09d1b1d commit 3e09219

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

apps/demo/tests/utils/email.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,23 @@ export class Email {
5050
}
5151

5252
async getEmailBody(email: string, messageId: string): Promise<string> {
53-
const result = await this.mailsac.messages.getBodyPlainText(email, messageId)
54-
55-
return String(result.data)
53+
let checks = 0
54+
/* eslint-disable no-await-in-loop */
55+
while (checks < MAX_EMAIL_CHECK) {
56+
try {
57+
const result = await this.mailsac.messages.getBodyPlainText(email, messageId)
58+
59+
return String(result.data)
60+
} catch (error) {
61+
if (checks < MAX_EMAIL_CHECK - 1) {
62+
await this.timeout(EMAIL_CHECK_INTERVAL)
63+
checks += 1
64+
} else {
65+
throw error
66+
}
67+
}
68+
}
69+
throw new Error(`Could not retrieve email body for message ${messageId}`)
5670
}
5771

5872
isApproveEmail(body: string): boolean {

0 commit comments

Comments
 (0)