fix(notifications): name TLS, protocol and envelope faults in email tests

A STARTTLS failure (port 465 set up as 587) and a protocol error now read as connection_failed, and an envelope or message refused without a reply code as upstream_rejected. They used to fall through to the 500 for an unnamed failure.

Refs #947
This commit is contained in:
Marc-André Bombeck committed 2026-09-13 14:50:33 +02:00
1 parent a11e5991cf
commit f81cdf8768
2 files changed
+49 -2

No files matched your search

@@ -237,3 +237,43 @@ describe("sendViaEmail — the failure names itself for the test button", () =>
expect(result.smtpCode).toBeUndefined();
});
});
describe("sendViaEmail — transport and envelope faults are named too", () => {
it.each([
["a TLS handshake failure", "ETLS", undefined, "connection_failed"],
["a protocol error", "EPROTOCOL", undefined, "connection_failed"],
[
"an envelope refused without a code",
"EENVELOPE",
undefined,
"upstream_rejected",
],
[
"a message refused without a code",
"EMESSAGE",
undefined,
"upstream_rejected",
],
[
"an envelope refused with a temporary code",
"EENVELOPE",
451,
"upstream_error",
],
])("%s", async (_label, code, responseCode, failureCode) => {
loadEmailConfigMock.mockReturnValue(transport);
sendMailMock.mockRejectedValue(
Object.assign(new Error(String(code)), {
code,
...(responseCode !== undefined ? { responseCode } : {}),
}),
);
const result = await sendViaEmail(
{ recipient: "you@example.com" },
payload(),
);
expect(result.failureCode).toBe(failureCode);
});
});
+9 -2
View File
@@ -106,13 +106,20 @@ function classifySmtpError(err: unknown): {
: code === "ECONNECTION" ||
code === "ESOCKET" ||
code === "EDNS" ||
code === "ECONNREFUSED"
code === "ECONNREFUSED" ||
// STARTTLS or TLS handshake failure (typically port 465 set up
// as 587 or the reverse) and a server that does not speak SMTP.
code === "ETLS" ||
code === "EPROTOCOL"
? "connection_failed"
: smtpCode !== undefined && smtpCode >= 500
? "upstream_rejected"
: smtpCode !== undefined && smtpCode >= 400
? "upstream_error"
: undefined;
: // An envelope or message refused without a reply code.
code === "EENVELOPE" || code === "EMESSAGE"
? "upstream_rejected"
: undefined;
const extras = {
...(failureCode ? { failureCode } : {}),
...(smtpCode !== undefined ? { smtpCode } : {}),