chore: add test for middleware error handling (#1453)

This commit is contained in:
Reed von Redwitz
2023-07-12 10:12:43 +02:00
committed by GitHub
parent 0d141b7153
commit 46ae49d654
4 changed files with 70 additions and 20 deletions
@@ -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>;
}