-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLU-330: Auto-retry cloudflare intermittent error codes 502,504,520 (#…
…769) ## Problem Postman email is returning 502, 504 and 520 intermittently. ## Solution Auto-retry for users
- Loading branch information
1 parent
bfa8974
commit 43d3dce
Showing
4 changed files
with
116 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | |
|
||
import HttpError from '@/errors/http' | ||
import PartialStepError from '@/errors/partial-error' | ||
import RetriableError from '@/errors/retriable-error' | ||
import StepError from '@/errors/step' | ||
|
||
import sendTransactionalEmail from '../../actions/send-transactional-email' | ||
|
@@ -316,6 +317,7 @@ describe('send transactional email', () => { | |
}, | ||
} as AxiosError), | ||
) | ||
|
||
await expect(sendTransactionalEmail.run($)).rejects.toThrowError(StepError) | ||
expect($.setActionItem).toHaveBeenCalledWith({ | ||
raw: { | ||
|
@@ -337,6 +339,57 @@ describe('send transactional email', () => { | |
}) | ||
}) | ||
|
||
it('should retry on 502, 504, 520', async () => { | ||
const recipients = [ | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
] | ||
$.step.parameters.destinationEmail = recipients.join(',') | ||
$.http.post = vi | ||
.fn() | ||
.mockResolvedValueOnce({ | ||
data: { | ||
params: { | ||
body: 'test body', | ||
subject: 'test subject', | ||
from: 'jack', | ||
reply_to: '[email protected]', | ||
}, | ||
}, | ||
}) | ||
.mockRejectedValueOnce( | ||
new HttpError({ | ||
response: { | ||
data: '<html>cloudflare error</html>', | ||
status: 500, | ||
statusText: 'Too Many Requests', | ||
}, | ||
} as AxiosError), | ||
) | ||
.mockRejectedValueOnce( | ||
new HttpError({ | ||
response: { | ||
data: '<html>cloudflare error</html>', | ||
status: 502, | ||
statusText: 'Too Many Requests', | ||
}, | ||
} as AxiosError), | ||
) | ||
|
||
await expect(sendTransactionalEmail.run($)).rejects.toThrow(RetriableError) | ||
expect($.setActionItem).toHaveBeenCalledWith({ | ||
raw: { | ||
status: ['ACCEPTED', 'ERROR', 'INTERMITTENT-ERROR'], | ||
recipient: recipients, | ||
subject: 'test subject', | ||
body: 'test body', | ||
from: 'jack', | ||
reply_to: '[email protected]', | ||
}, | ||
}) | ||
}) | ||
|
||
it('should only retry to non-accepted emails', async () => { | ||
const recipients = [ | ||
'[email protected]', | ||
|
@@ -367,4 +420,41 @@ describe('send transactional email', () => { | |
}) | ||
expect(mocks.sendBlacklistEmail).not.toHaveBeenCalled() | ||
}) | ||
|
||
it('should only retry to non-accepted emails', async () => { | ||
const recipients = [ | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
] | ||
$.step.parameters.destinationEmail = recipients.join(',') | ||
$.getLastExecutionStep = vi.fn().mockResolvedValueOnce({ | ||
status: 'success', | ||
errorDetails: 'error error', | ||
dataOut: { | ||
status: [ | ||
'BLACKLISTED', | ||
'ACCEPTED', | ||
'INTERMITTENT-ERROR', | ||
'ERROR', | ||
'RATE-LIMITED', | ||
], | ||
recipient: recipients, | ||
}, | ||
}) | ||
await expect(sendTransactionalEmail.run($)).resolves.not.toThrow() | ||
expect($.http.post).toBeCalledTimes(4) | ||
expect($.setActionItem).toHaveBeenCalledWith({ | ||
raw: { | ||
status: ['ACCEPTED', 'ACCEPTED', 'ACCEPTED', 'ACCEPTED', 'ACCEPTED'], | ||
recipient: recipients, | ||
subject: 'test subject', | ||
body: 'test body', | ||
from: 'jack', | ||
reply_to: '[email protected]', | ||
}, | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters