fix(notifications): record a relay refusal at warn, not error

A 502 from a channel test reports the user's relay or mail setup, not a fault on this server, yet the status alone raised every press to an error-level event. The event builder gains a ceiling for the status-derived level, and the test routes cap it at warn on the 502 path. The 500 for an unnamed failure stays at error, and explicit elevations are unaffected.

The notifications guide notes that a reverse proxy which replaces 5xx pages hides the detail, so the card falls back to Test failed.

Refs #947
This commit is contained in:
Marc-André Bombeck committed 2026-09-13 14:50:32 +02:00
1 parent f89dda81a6
commit 6a663dfc27
5 files changed
+78 -5

No files matched your search

@@ -110,3 +110,33 @@ describe("WideEventBuilder.setHttp", () => {
expect(evt.toJSON().http).toBeUndefined();
});
});
describe("WideEventBuilder.capStatusLevel", () => {
it("derives error from a 5xx by default", () => {
const evt = new WideEventBuilder("http");
evt.finish(502);
expect(evt.toJSON().level).toBe("error");
});
it("keeps a capped 5xx at warn", () => {
const evt = new WideEventBuilder("http");
evt.capStatusLevel("warn");
evt.finish(502);
expect(evt.toJSON().level).toBe("warn");
});
it("does not lower an explicit elevation", () => {
const evt = new WideEventBuilder("http");
evt.capStatusLevel("warn");
evt.elevateLevel("error");
evt.finish(502);
expect(evt.toJSON().level).toBe("error");
});
it("leaves a 4xx at warn under the cap", () => {
const evt = new WideEventBuilder("http");
evt.capStatusLevel("warn");
evt.finish(422);
expect(evt.toJSON().level).toBe("warn");
});
});
+23 -2
View File
@@ -43,6 +43,7 @@ export class WideEventBuilder {
private event: Partial<WideEvent>;
private startTime: number;
private highestLevel: LogLevel = "info";
private statusLevelCeiling: LogLevel = "error";
constructor(kind: EventKind = "http") {
this.startTime = performance.now();
@@ -239,6 +240,18 @@ export class WideEventBuilder {
return this;
}
/**
* Ceiling for the level `finish()` derives from the HTTP status. A route
* whose 5xx reports someone else's refusal (a user's relay answering a
* test with 400) caps it at `warn`, so a user's configuration does not
* raise an operator-facing error. `elevateLevel` calls and thrown errors
* are unaffected.
*/
capStatusLevel(level: LogLevel): this {
this.statusLevelCeiling = level;
return this;
}
/** Request/Operation beenden, Duration berechnen */
finish(httpStatus?: number): this {
this.event.duration_ms = Math.round(performance.now() - this.startTime);
@@ -256,8 +269,16 @@ export class WideEventBuilder {
this.event.http.status = httpStatus;
}
if (httpStatus !== undefined) {
if (httpStatus >= 500) this.elevateLevel("error");
else if (httpStatus >= 400) this.elevateLevel("warn");
const derived: LogLevel | null =
httpStatus >= 500 ? "error" : httpStatus >= 400 ? "warn" : null;
if (derived) {
this.elevateLevel(
LOG_LEVEL_PRIORITY[derived] >
LOG_LEVEL_PRIORITY[this.statusLevelCeiling]
? this.statusLevelCeiling
: derived,
);
}
}
this.event.level = this.highestLevel;
return this;