chore: add test for middleware error handling (#1453)
This commit is contained in:
@@ -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>;
|
||||
}
|
||||
Reference in New Issue
Block a user