fix: remove error frame HTML for non-dev mode (#2133)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
This commit is contained in:
co-authored by
Marvin Hagemeister
parent
c4e09d1cef
commit
96644f5e22
+23
-24
@@ -359,32 +359,31 @@ export async function render<Data>(
|
|||||||
pluginRenderResults: renderResults,
|
pluginRenderResults: renderResults,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Dev only: Append error overlay
|
// Append error overlay in dev mode
|
||||||
const devErrorUrl = withBase(DEV_ERROR_OVERLAY_URL, basePath);
|
if (opts.context.config.dev) {
|
||||||
if (
|
const devErrorUrl = withBase(DEV_ERROR_OVERLAY_URL, basePath);
|
||||||
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) {
|
||||||
const url = new URL(devErrorUrl, "https://localhost/");
|
let message = error.message;
|
||||||
if (error instanceof Error) {
|
const idx = message.indexOf("\n");
|
||||||
let message = error.message;
|
if (idx > -1) message = message.slice(0, idx);
|
||||||
const idx = message.indexOf("\n");
|
url.searchParams.append("message", message);
|
||||||
if (idx > -1) message = message.slice(0, idx);
|
if (error.stack) {
|
||||||
url.searchParams.append("message", message);
|
const stack = colors.stripAnsiCode(error.stack);
|
||||||
if (error.stack) {
|
url.searchParams.append("stack", stack);
|
||||||
const stack = colors.stripAnsiCode(error.stack);
|
}
|
||||||
url.searchParams.append("stack", stack);
|
} else {
|
||||||
|
url.searchParams.append("message", String(error));
|
||||||
|
}
|
||||||
|
if (opts.codeFrame) {
|
||||||
|
const codeFrame = colors.stripAnsiCode(opts.codeFrame);
|
||||||
|
url.searchParams.append("code-frame", codeFrame);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
url.searchParams.append("message", String(error));
|
|
||||||
}
|
|
||||||
if (opts.codeFrame) {
|
|
||||||
const codeFrame = colors.stripAnsiCode(opts.codeFrame);
|
|
||||||
url.searchParams.append("code-frame", codeFrame);
|
|
||||||
}
|
|
||||||
|
|
||||||
result.bodyHtml +=
|
result.bodyHtml +=
|
||||||
`<iframe id="fresh-error-overlay" src="${url.pathname}?${url.searchParams.toString()}" style="unset: all; position: fixed; top: 0; left: 0; z-index: 99999; width: 100%; height: 100%; border: none;"></iframe>`;
|
`<iframe id="fresh-error-overlay" src="${url.pathname}?${url.searchParams.toString()}" style="unset: all; position: fixed; top: 0; left: 0; z-index: 99999; width: 100%; height: 100%; border: none;"></iframe>`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render outer document up to `<body>`
|
// Render outer document up to `<body>`
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export {
|
|||||||
assert,
|
assert,
|
||||||
assertEquals,
|
assertEquals,
|
||||||
assertExists,
|
assertExists,
|
||||||
|
AssertionError,
|
||||||
assertMatch,
|
assertMatch,
|
||||||
assertNotEquals,
|
assertNotEquals,
|
||||||
assertNotMatch,
|
assertNotMatch,
|
||||||
|
|||||||
+23
-1
@@ -1,5 +1,10 @@
|
|||||||
import { STATUS_CODE } from "../server.ts";
|
import { STATUS_CODE } from "../server.ts";
|
||||||
import { assertEquals, assertStringIncludes } from "./deps.ts";
|
import {
|
||||||
|
assertEquals,
|
||||||
|
AssertionError,
|
||||||
|
assertRejects,
|
||||||
|
assertStringIncludes,
|
||||||
|
} from "./deps.ts";
|
||||||
import { getErrorOverlay, withFakeServe } from "./test_utils.ts";
|
import { getErrorOverlay, withFakeServe } from "./test_utils.ts";
|
||||||
|
|
||||||
Deno.test("error page rendered", async () => {
|
Deno.test("error page rendered", async () => {
|
||||||
@@ -15,3 +20,20 @@ Deno.test("error page rendered", async () => {
|
|||||||
assertStringIncludes(stack, `at render`);
|
assertStringIncludes(stack, `at render`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test("error page rendered without error overlay", async () => {
|
||||||
|
await withFakeServe("./tests/fixture_error/main.ts", async (server) => {
|
||||||
|
const resp = await server.get("/");
|
||||||
|
assertEquals(resp.status, STATUS_CODE.InternalServerError);
|
||||||
|
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
|
||||||
|
const body = await resp.text();
|
||||||
|
assertStringIncludes(body, "<p>500 page</p>");
|
||||||
|
|
||||||
|
await assertRejects(
|
||||||
|
() => getErrorOverlay(server, "/"),
|
||||||
|
AssertionError,
|
||||||
|
undefined,
|
||||||
|
"Missing fresh error overlay",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
+3
-2
@@ -171,9 +171,10 @@ export async function getErrorOverlay(
|
|||||||
url: string,
|
url: string,
|
||||||
): Promise<{ title: string; codeFrame: boolean; stack: string }> {
|
): Promise<{ title: string; codeFrame: boolean; stack: string }> {
|
||||||
const doc = await server.getHtml(url);
|
const doc = await server.getHtml(url);
|
||||||
const iframe = doc.querySelector(
|
const iframe = doc.querySelector<HTMLIFrameElement>(
|
||||||
"#fresh-error-overlay",
|
"#fresh-error-overlay",
|
||||||
) as HTMLIFrameElement;
|
);
|
||||||
|
assert(iframe, "Missing fresh error overlay");
|
||||||
|
|
||||||
const doc2 = await server.getHtml(iframe.src);
|
const doc2 = await server.getHtml(iframe.src);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user