Stability round two: no language links on POST-rendered pages, scoped observers, Vary only where it varies
CI / full-gate (push) Successful in 2m37s
CI / full-gate (push) Successful in 2m37s
This commit is contained in:
@@ -44,11 +44,12 @@ test("runRequestHooks short-circuits on the first RouteResult (with its plugin);
|
||||
|
||||
test("runResponseHooks runs every onResponse as an observer with the result; a throw fails", async () => {
|
||||
const seen: unknown[] = [];
|
||||
const contextFor = () => ctx; // each observer gets a context scoped to its own plugin
|
||||
await runResponseHooks([
|
||||
plugin("a", { onResponse: (_c, r) => void seen.push(r) }),
|
||||
plugin("b", {}), // no onResponse → skipped
|
||||
], ctx, { html: "ok" });
|
||||
], contextFor, { html: "ok" });
|
||||
assert.deepEqual(seen, [{ html: "ok" }]);
|
||||
|
||||
await assert.rejects(runResponseHooks([plugin("x", { onResponse: () => { throw new Error("boom"); } })], ctx, null), /boom/);
|
||||
await assert.rejects(runResponseHooks([plugin("x", { onResponse: () => { throw new Error("boom"); } })], contextFor, null), /boom/);
|
||||
});
|
||||
|
||||
@@ -29,7 +29,14 @@ export async function runRequestHooks(
|
||||
}
|
||||
|
||||
// After a route handler produces its result. Observers only — the return value is ignored, so a
|
||||
// hook cannot change the response; a throw fails the request.
|
||||
export async function runResponseHooks(plugins: Plugin[], ctx: RequestContext, result: RouteResult | null): Promise<void> {
|
||||
for (const plugin of plugins) await plugin.hooks?.onResponse?.(ctx, result);
|
||||
// hook cannot change the response; a throw fails the request. Each observer gets a context scoped to
|
||||
// its own plugin, like onRequest, so `ctx.t` is never another plugin's translator.
|
||||
export async function runResponseHooks(
|
||||
plugins: Plugin[],
|
||||
contextFor: (pluginId: string) => RequestContext,
|
||||
result: RouteResult | null,
|
||||
): Promise<void> {
|
||||
for (const plugin of plugins) {
|
||||
if (plugin.hooks?.onResponse) await plugin.hooks.onResponse(contextFor(plugin.id), result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user