@veducio/keja 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -60,4 +60,18 @@ describe("runMiddleware", () => {
|
|
|
60
60
|
).rejects.toThrow(`Middleware cannot pass reserved field ${key}`);
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
|
+
|
|
64
|
+
it("rejects next() when the rest of the chain does not return a Response", async () => {
|
|
65
|
+
const step = defineMiddleware(async ({ next }) => {
|
|
66
|
+
const response = await next();
|
|
67
|
+
return response;
|
|
68
|
+
});
|
|
69
|
+
await expect(
|
|
70
|
+
runMiddleware(
|
|
71
|
+
[{ definition: step, allowFields: true }],
|
|
72
|
+
context,
|
|
73
|
+
() => undefined as never,
|
|
74
|
+
),
|
|
75
|
+
).rejects.toThrow("next() must resolve to a Response");
|
|
76
|
+
});
|
|
63
77
|
});
|
package/src/route/middleware.ts
CHANGED
|
@@ -128,7 +128,11 @@ export async function runMiddleware(
|
|
|
128
128
|
}
|
|
129
129
|
Object.assign(fields, passed);
|
|
130
130
|
}
|
|
131
|
-
|
|
131
|
+
const nextResponse = await dispatch();
|
|
132
|
+
if (!(nextResponse instanceof Response)) {
|
|
133
|
+
throw new Error("next() must resolve to a Response");
|
|
134
|
+
}
|
|
135
|
+
return nextResponse;
|
|
132
136
|
},
|
|
133
137
|
});
|
|
134
138
|
if (!(response instanceof Response)) {
|