fix: don't show error overlay on HttpError < 500 (#2462)
This commit is contained in:
+29
@@ -56,6 +56,35 @@ Deno.test("error overlay - should not be visible for HttpError <500", async () =
|
|||||||
expect(res.status).toEqual(500);
|
expect(res.status).toEqual(500);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test(
|
||||||
|
"error overlay - should not be visible for HttpError <500 #2",
|
||||||
|
async () => {
|
||||||
|
const app = new App();
|
||||||
|
app.use(devErrorOverlay());
|
||||||
|
app.config.mode = "development";
|
||||||
|
app
|
||||||
|
.use(async (ctx) => {
|
||||||
|
try {
|
||||||
|
return await ctx.next();
|
||||||
|
} catch (err) {
|
||||||
|
return ctx.render(<p>ok</p>);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.get("/", () => {
|
||||||
|
throw new HttpError(404);
|
||||||
|
});
|
||||||
|
|
||||||
|
const server = new FakeServer(await app.handler());
|
||||||
|
const res = await server.get("/", {
|
||||||
|
headers: {
|
||||||
|
accept: "text/html",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const content = await res.text();
|
||||||
|
expect(content).not.toContain("fresh-error-overlay");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
Deno.test("error overlay - should not be visible in prod", async () => {
|
Deno.test("error overlay - should not be visible in prod", async () => {
|
||||||
const app = new App();
|
const app = new App();
|
||||||
app.use(devErrorOverlay());
|
app.use(devErrorOverlay());
|
||||||
@@ -31,6 +31,7 @@ import {
|
|||||||
} from "../../dev/middlewares/error_overlay/code_frame.tsx";
|
} from "../../dev/middlewares/error_overlay/code_frame.tsx";
|
||||||
import * as colors from "@std/fmt/colors";
|
import * as colors from "@std/fmt/colors";
|
||||||
import { escape as escapeHtml } from "@std/html";
|
import { escape as escapeHtml } from "@std/html";
|
||||||
|
import { HttpError } from "../../error.ts";
|
||||||
|
|
||||||
const enum OptionsType {
|
const enum OptionsType {
|
||||||
ATTR = "attr",
|
ATTR = "attr",
|
||||||
@@ -502,6 +503,11 @@ export function ShowErrorOverlay() {
|
|||||||
|
|
||||||
if (error === null || error === undefined) return null;
|
if (error === null || error === undefined) return null;
|
||||||
|
|
||||||
|
// Ignore HTTP errors <500
|
||||||
|
if (error instanceof HttpError && error.status < 500) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const basePath = ctx.config.basePath;
|
const basePath = ctx.config.basePath;
|
||||||
|
|
||||||
const searchParams = new URLSearchParams();
|
const searchParams = new URLSearchParams();
|
||||||
|
|||||||
Reference in New Issue
Block a user