feat: add nice error page during development (#122)
Co-authored-by: Luca Casonato <hello@lcas.dev>
This commit is contained in:
co-authored by
Luca Casonato
parent
837d2a7f5e
commit
026ed86f40
@@ -0,0 +1,20 @@
|
||||
import { ServerContext } from "../server.ts";
|
||||
import { assert, assertEquals, assertStringIncludes } from "./deps.ts";
|
||||
import manifest from "./fixture_error/fresh.gen.ts";
|
||||
|
||||
const ctx = await ServerContext.fromManifest(manifest);
|
||||
const router = ctx.handler();
|
||||
|
||||
Deno.test("error page rendered", async () => {
|
||||
const resp = await router(new Request("https://fresh.deno.dev/"));
|
||||
assert(resp);
|
||||
assertEquals(resp.status, 500);
|
||||
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
|
||||
const body = await resp.text();
|
||||
assertStringIncludes(
|
||||
body,
|
||||
`An error occured during route handling or page rendering.`,
|
||||
);
|
||||
assertStringIncludes(body, `Error: boom!`);
|
||||
assertStringIncludes(body, `at render`);
|
||||
});
|
||||
@@ -1,15 +0,0 @@
|
||||
# fresh project
|
||||
|
||||
### Usage
|
||||
|
||||
Start the project:
|
||||
|
||||
```
|
||||
deno run -A --watch main.ts
|
||||
```
|
||||
|
||||
After adding, removing, or moving a page in the `pages` directory, run:
|
||||
|
||||
```
|
||||
fresh routes
|
||||
```
|
||||
@@ -0,0 +1 @@
|
||||
export * from "../../runtime.ts";
|
||||
@@ -0,0 +1,15 @@
|
||||
// DO NOT EDIT. This file is generated by `fresh`.
|
||||
// This file SHOULD be checked into source version control.
|
||||
// To update this file, run `fresh routes`.
|
||||
|
||||
import * as $0 from "./routes/index.tsx";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
"./routes/index.tsx": $0,
|
||||
},
|
||||
islands: {},
|
||||
baseUrl: import.meta.url,
|
||||
};
|
||||
|
||||
export default manifest;
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference no-default-lib="true" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
/// <reference lib="deno.ns" />
|
||||
/// <reference lib="deno.unstable" />
|
||||
|
||||
import { start } from "./server_deps.ts";
|
||||
import manifest from "./fresh.gen.ts";
|
||||
|
||||
await start(manifest);
|
||||
@@ -0,0 +1,6 @@
|
||||
/** @jsx h */
|
||||
import { h } from "../client_deps.ts";
|
||||
|
||||
export default function Home(): null {
|
||||
throw new Error("boom!");
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from "../../server.ts";
|
||||
Reference in New Issue
Block a user