mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 13:52:20 +00:00
fix(admin): show each channel's cause in the notification test toast
The admin test response carried a code and status per channel that nothing rendered. The toast now lists each failing channel with the translated cause and the HTTP status or SMTP code. The relay reply is no longer part of that response, and the ntfy error no longer echoes the topic, which the sender treats as a secret. Refs #947
This commit is contained in:
1 parent
2480c9fa55
commit
32eaf7a29e
5 files changed
+157
-25
No files matched your search
@@ -347,6 +347,7 @@ describe("POST /api/admin/notifications/test — a failure keeps its cause (#947
|
||||
upstreamStatus: 400,
|
||||
});
|
||||
expect(body.data.results[0].error).toContain("HTTP 400");
|
||||
expect(body.data.results[0].error).not.toContain("hl-test");
|
||||
});
|
||||
|
||||
it("tests the webhook channel rather than calling it unknown", async () => {
|
||||
@@ -372,8 +373,9 @@ describe("POST /api/admin/notifications/test — a failure keeps its cause (#947
|
||||
success: false,
|
||||
errorCode: "upstream_rejected",
|
||||
upstreamStatus: 400,
|
||||
upstreamBody: "priority must be an integer",
|
||||
});
|
||||
// The relay body belongs to the settings card, not the admin toast.
|
||||
expect(body.data.results[0].upstreamBody).toBeUndefined();
|
||||
});
|
||||
|
||||
it("tests the email channel and forwards the SMTP code", async () => {
|
||||
|
||||
@@ -72,11 +72,12 @@ async function ensureTelegramChannel(userId: string): Promise<boolean> {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** The admin toast renders `errorCode` and the status; the relay body stays on the settings card. */
|
||||
type TestResult = {
|
||||
channel: string;
|
||||
success: boolean;
|
||||
error?: string;
|
||||
} & TestFailureDetail;
|
||||
} & Omit<TestFailureDetail, "upstreamBody">;
|
||||
|
||||
/**
|
||||
* A failed HTTP or SMTP send, with the code, status and SMTP reply code the
|
||||
@@ -87,21 +88,26 @@ function failedSend(
|
||||
channel: string,
|
||||
label: string,
|
||||
result: SendOutcome,
|
||||
context?: string,
|
||||
): TestResult {
|
||||
const detail: TestFailureDetail = result.errorCode
|
||||
? { errorCode: result.errorCode }
|
||||
const { errorCode, upstreamStatus, smtpCode } = result.errorCode
|
||||
? {
|
||||
errorCode: result.errorCode,
|
||||
upstreamStatus: undefined,
|
||||
smtpCode: undefined,
|
||||
}
|
||||
: testFailureDetail(result);
|
||||
const cause = result.errorCode
|
||||
? `refused by the private-origin policy (${result.errorCode})`
|
||||
: detail.errorCode
|
||||
? testFailureSentence(label, detail)
|
||||
: errorCode
|
||||
? testFailureSentence(label, { errorCode, upstreamStatus, smtpCode })
|
||||
: (result.reason ?? "send failed");
|
||||
return {
|
||||
channel,
|
||||
success: false,
|
||||
error: context ? `${cause} (${context})` : cause,
|
||||
...detail,
|
||||
error: cause,
|
||||
...(errorCode ? { errorCode } : {}),
|
||||
...(upstreamStatus !== undefined ? { upstreamStatus } : {}),
|
||||
...(smtpCode !== undefined ? { smtpCode } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -205,14 +211,8 @@ export const POST = apiHandler(async () => {
|
||||
const ntfyResult = await sendViaNtfy(config, payload);
|
||||
success = ntfyResult.ok;
|
||||
if (!success) {
|
||||
results.push(
|
||||
failedSend(
|
||||
"NTFY",
|
||||
"The ntfy server",
|
||||
ntfyResult,
|
||||
`topic: ${config.topic}`,
|
||||
),
|
||||
);
|
||||
// The topic is not echoed: on a public server it is the secret.
|
||||
results.push(failedSend("NTFY", "The ntfy server", ntfyResult));
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in new issue
Block a user