fix: use real 500 error page in dev mode (#2134)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
This commit is contained in:
co-authored by
Marvin Hagemeister
parent
e78c6a90af
commit
c4e09d1cef
@@ -226,21 +226,7 @@ export async function extractRoutes(
|
||||
url,
|
||||
name,
|
||||
component,
|
||||
handler: (req, ctx) => {
|
||||
if (config.dev) {
|
||||
const prevComp = error.component;
|
||||
error.component = DefaultErrorHandler;
|
||||
try {
|
||||
return ctx.render();
|
||||
} finally {
|
||||
error.component = prevComp;
|
||||
}
|
||||
}
|
||||
|
||||
return handler
|
||||
? handler(req, ctx)
|
||||
: router.defaultErrorHandler(req, ctx, ctx.error);
|
||||
},
|
||||
handler: handler ?? router.defaultErrorHandler,
|
||||
csp: Boolean(routeConfig?.csp ?? false),
|
||||
appWrapper: !routeConfig?.skipAppWrapper,
|
||||
inheritLayouts: !routeConfig?.skipInheritedLayouts,
|
||||
|
||||
@@ -359,9 +359,12 @@ export async function render<Data>(
|
||||
pluginRenderResults: renderResults,
|
||||
});
|
||||
|
||||
// Append error overlay
|
||||
// Dev only: Append error overlay
|
||||
const devErrorUrl = withBase(DEV_ERROR_OVERLAY_URL, basePath);
|
||||
if (error !== undefined && url.pathname !== devErrorUrl) {
|
||||
if (
|
||||
error !== undefined && url.pathname !== devErrorUrl &&
|
||||
opts.context.config.dev
|
||||
) {
|
||||
const url = new URL(devErrorUrl, "https://localhost/");
|
||||
if (error instanceof Error) {
|
||||
let message = error.message;
|
||||
|
||||
@@ -82,10 +82,9 @@ export function defaultOtherHandler(_req: Request): Response {
|
||||
|
||||
export function defaultErrorHandler(
|
||||
_req: Request,
|
||||
_ctx: FreshContext,
|
||||
err: unknown,
|
||||
ctx: FreshContext,
|
||||
): Response {
|
||||
console.error(err);
|
||||
console.error(ctx.error);
|
||||
|
||||
return new Response(null, {
|
||||
status: 500,
|
||||
|
||||
Reference in New Issue
Block a user