fix(notifications): answer a failed channel test with its cause

The webhook, ntfy and email test routes turned every delivery failure into a bare 500, so the settings card could only say "Test failed" while the server knew the relay had answered 400. A failure at the other end, or on the way to it, is now a 502 with meta.errorCode, the upstream HTTP status or SMTP reply code, and for webhook and ntfy what the relay answered when that is short and holds no credential. The codes reuse the test card's vocabulary; upstream_rejected is new, for a relay that accepted the connection and refused the payload. The private-origin 422 is unchanged, and only a failure the server cannot name stays a 500.

The guard that pinned the bare 500 now asserts the opposite, with the reason in its name.

The admin fan-out test reports the same code and status per channel, and tests the webhook and email channels, which it used to list as an unknown channel type.

Refs #947
This commit is contained in:
Marc-André Bombeck committed 2026-09-13 14:10:35 +02:00
1 parent 8c345f600e
commit f6a890df8a
11 files changed
+744 -39

No files matched your search

+9 -1
View File
@@ -6,6 +6,7 @@ import type { WebhookChannelConfig } from "@/lib/notifications/types";
import { checkRateLimit } from "@/lib/rate-limit";
import { apiHandler, requireAuth } from "@/lib/api-handler";
import { annotate } from "@/lib/logging/context";
import { answerTestDeliveryFailure } from "@/lib/notifications/test-delivery-failure";
/**
* POST: send a test notification via the configured generic webhook.
@@ -57,7 +58,14 @@ export const POST = apiHandler(async () => {
{ errorCode: result.errorCode },
);
}
return apiError("Failed to send test message", 500);
// The relay, or the way to it, failed: 502 with the upstream status and
// what it said, so the card can show "the relay answered 400" instead
// of "Test failed" (#947). Only an unnamed internal fault is a 500.
return answerTestDeliveryFailure(result, {
channel: "webhook",
label: "The webhook",
fallbackMessage: "Failed to send test message",
});
}
annotate({