Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit 546d797

Browse files
committed
fix: add better status code parsing for accurate retries
1 parent cf7eb5e commit 546d797

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

index.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1662,13 +1662,32 @@ class ForwardEmail {
16621662
// if no recipients return early with bounces joined together
16631663
if (_.isEmpty(recipients)) {
16641664
if (_.isEmpty(bounces)) throw new CustomError('Invalid recipients');
1665+
const codes = bounces.map((bounce) => {
1666+
if (_.isNumber(bounce.err.responseCode))
1667+
return bounce.err.responseCode;
1668+
if (
1669+
_.isString(bounce.err.code) &&
1670+
RETRY_CODES.includes(bounce.err.code)
1671+
)
1672+
return CODES_TO_RESPONSE_CODES[bounce.err.code];
1673+
if (
1674+
(bounce.err.code &&
1675+
HTTP_RETRY_ERROR_CODES.has(bounce.err.code)) ||
1676+
(_.isNumber(bounce.err.status) &&
1677+
HTTP_RETRY_STATUS_CODES.has(bounce.err.status))
1678+
)
1679+
return 421;
1680+
return 550;
1681+
});
1682+
const [code] = codes.sort();
16651683
throw new CustomError(
16661684
bounces
16671685
.map(
16681686
(bounce) =>
16691687
`Error for ${bounce.address} of "${bounce.err.message}"`
16701688
)
1671-
.join(', ')
1689+
.join(', '),
1690+
code
16721691
);
16731692
}
16741693

@@ -1926,6 +1945,12 @@ class ForwardEmail {
19261945
RETRY_CODES.includes(bounce.err.code)
19271946
)
19281947
return CODES_TO_RESPONSE_CODES[bounce.err.code];
1948+
if (
1949+
(bounce.err.code && HTTP_RETRY_ERROR_CODES.has(bounce.err.code)) ||
1950+
(_.isNumber(bounce.err.status) &&
1951+
HTTP_RETRY_STATUS_CODES.has(bounce.err.status))
1952+
)
1953+
return 421;
19291954
return 550;
19301955
});
19311956

0 commit comments

Comments
 (0)