import type { Middleware } from "./common"; // A middleware has to be a function of type Middleware const prettyError: Middleware = async (request, env, _ctx, middlewareCtx) => { try { const response = await middlewareCtx.next(request, env); return response; } catch (e: any) { const html = `
${e.stack}`; return new Response(html, { status: 500, headers: { "Content-Type": "text/html;charset=utf-8" }, }); } }; export default prettyError;