chore: add test for middleware error handling (#1453)
This commit is contained in:
+24
-20
@@ -37,16 +37,18 @@ import * as $31 from "./routes/layeredMdw/nesting/[tenant]/[environment]/[id].ts
|
||||
import * as $32 from "./routes/layeredMdw/nesting/[tenant]/[environment]/_middleware.ts";
|
||||
import * as $33 from "./routes/layeredMdw/nesting/[tenant]/_middleware.ts";
|
||||
import * as $34 from "./routes/layeredMdw/nesting/_middleware.ts";
|
||||
import * as $35 from "./routes/middleware_root.ts";
|
||||
import * as $36 from "./routes/not_found.ts";
|
||||
import * as $37 from "./routes/params.tsx";
|
||||
import * as $38 from "./routes/props/[id].tsx";
|
||||
import * as $39 from "./routes/state-in-props/_middleware.ts";
|
||||
import * as $40 from "./routes/state-in-props/index.tsx";
|
||||
import * as $41 from "./routes/static.tsx";
|
||||
import * as $42 from "./routes/status_overwrite.tsx";
|
||||
import * as $43 from "./routes/umlaut-äöüß.tsx";
|
||||
import * as $44 from "./routes/wildcard.tsx";
|
||||
import * as $35 from "./routes/middleware-error-handler/_middleware.ts";
|
||||
import * as $36 from "./routes/middleware-error-handler/index.tsx";
|
||||
import * as $37 from "./routes/middleware_root.ts";
|
||||
import * as $38 from "./routes/not_found.ts";
|
||||
import * as $39 from "./routes/params.tsx";
|
||||
import * as $40 from "./routes/props/[id].tsx";
|
||||
import * as $41 from "./routes/state-in-props/_middleware.ts";
|
||||
import * as $42 from "./routes/state-in-props/index.tsx";
|
||||
import * as $43 from "./routes/static.tsx";
|
||||
import * as $44 from "./routes/status_overwrite.tsx";
|
||||
import * as $45 from "./routes/umlaut-äöüß.tsx";
|
||||
import * as $46 from "./routes/wildcard.tsx";
|
||||
import * as $$0 from "./islands/Counter.tsx";
|
||||
import * as $$1 from "./islands/MultipleCounters.tsx";
|
||||
import * as $$2 from "./islands/ReturningNull.tsx";
|
||||
@@ -94,16 +96,18 @@ const manifest = {
|
||||
"./routes/layeredMdw/nesting/[tenant]/[environment]/_middleware.ts": $32,
|
||||
"./routes/layeredMdw/nesting/[tenant]/_middleware.ts": $33,
|
||||
"./routes/layeredMdw/nesting/_middleware.ts": $34,
|
||||
"./routes/middleware_root.ts": $35,
|
||||
"./routes/not_found.ts": $36,
|
||||
"./routes/params.tsx": $37,
|
||||
"./routes/props/[id].tsx": $38,
|
||||
"./routes/state-in-props/_middleware.ts": $39,
|
||||
"./routes/state-in-props/index.tsx": $40,
|
||||
"./routes/static.tsx": $41,
|
||||
"./routes/status_overwrite.tsx": $42,
|
||||
"./routes/umlaut-äöüß.tsx": $43,
|
||||
"./routes/wildcard.tsx": $44,
|
||||
"./routes/middleware-error-handler/_middleware.ts": $35,
|
||||
"./routes/middleware-error-handler/index.tsx": $36,
|
||||
"./routes/middleware_root.ts": $37,
|
||||
"./routes/not_found.ts": $38,
|
||||
"./routes/params.tsx": $39,
|
||||
"./routes/props/[id].tsx": $40,
|
||||
"./routes/state-in-props/_middleware.ts": $41,
|
||||
"./routes/state-in-props/index.tsx": $42,
|
||||
"./routes/static.tsx": $43,
|
||||
"./routes/status_overwrite.tsx": $44,
|
||||
"./routes/umlaut-äöüß.tsx": $45,
|
||||
"./routes/wildcard.tsx": $46,
|
||||
},
|
||||
islands: {
|
||||
"./islands/Counter.tsx": $$0,
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
||||
|
||||
export async function handler(
|
||||
_req: Request,
|
||||
ctx: MiddlewareHandlerContext,
|
||||
) {
|
||||
try {
|
||||
ctx.state.flag = true;
|
||||
return await ctx.next();
|
||||
} catch (error) {
|
||||
console.log("we're very thoroughly dealing with this error here: " + error);
|
||||
throw Error("don't show the full error for security purposes");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Handlers, PageProps } from "$fresh/server.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
GET(req, ctx) {
|
||||
return ctx.render(ctx.state.flag);
|
||||
},
|
||||
};
|
||||
|
||||
export default function Home(props: PageProps<boolean>) {
|
||||
if (props.data) {
|
||||
throw Error("i'm erroring on purpose");
|
||||
}
|
||||
return <div>this won't get shown</div>;
|
||||
}
|
||||
@@ -652,6 +652,24 @@ Deno.test("middleware destination", async (t) => {
|
||||
});
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "middleware catch error",
|
||||
fn: async () => {
|
||||
const resp = await handler(
|
||||
new Request(
|
||||
"https://fresh.deno.dev/middleware-error-handler",
|
||||
),
|
||||
);
|
||||
assert(resp);
|
||||
assertEquals(resp.status, Status.InternalServerError);
|
||||
const body = await resp.text();
|
||||
assertStringIncludes(
|
||||
body,
|
||||
"500 internal error: don't show the full error for security purposes",
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test("experimental Deno.serve", {
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
|
||||
Reference in New Issue
Block a user