diff --git a/src/middleware/with-response-object-check.ts b/src/middleware/with-response-object-check.ts index 9f8cae0..89d9e03 100644 --- a/src/middleware/with-response-object-check.ts +++ b/src/middleware/with-response-object-check.ts @@ -9,8 +9,10 @@ export const withResponseObjectCheck: Middleware< const rawResponse = await next(req, ctx) if (typeof rawResponse === "object" && !(rawResponse instanceof Response)) { + const method = req.method?.toUpperCase() ?? "UNKNOWN" + const path = new URL(req.url).pathname throw new Error( - "Use ctx.json({...}) instead of returning an object directly." + `Route ${method} ${path} returned a plain object. Use ctx.json({...}) instead of returning an object directly.` ) } diff --git a/tests/errors/do-not-allow-raw-json.test.ts b/tests/errors/do-not-allow-raw-json.test.ts index 8682796..c27b832 100644 --- a/tests/errors/do-not-allow-raw-json.test.ts +++ b/tests/errors/do-not-allow-raw-json.test.ts @@ -31,6 +31,7 @@ test("should throw an error when responding with raw JSON", async (t) => { const { data } = await axios.get("/", { validateStatus: () => true, }) + t.true(data.error.includes("Route GET /")) t.true( data.error.includes( "Use ctx.json({...}) instead of returning an object directly"