Skip to content

Commit 377ebd1

Browse files
authored
Merge branch 'main' into remove-ResolvedFreshConfig
2 parents e04f552 + 45ce7e3 commit 377ebd1

5 files changed

Lines changed: 74 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,6 @@ jobs:
5050

5151
- name: Run tests
5252
run: deno task test
53+
54+
- name: Check docs
55+
run: deno task check:docs

deno.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"build-www": "deno task --cwd=www build",
2323
"screenshot": "deno run -A www/utils/screenshot.ts",
2424
"check:types": "deno check src/**/*.ts src/**/*.tsx tests/**/*.ts tests/**/*.tsx update/**/*.ts plugin-tailwindcss/**/*.ts init/**/*.ts",
25+
"check:docs": "deno run -A tools/check_docs.ts",
2526
"ok": "deno fmt --check && deno lint && deno task check:types && deno task test",
2627
"test:www": "deno test -A www/main_test.*",
2728
"release": "deno run -A tools/release.ts"
@@ -40,6 +41,8 @@
4041
"exclude": ["**/*_test.*", "src/__OLD/**", "*.todo"]
4142
},
4243
"imports": {
44+
"@deno/doc": "jsr:@deno/doc@^0.172.0",
45+
"@std/collections": "jsr:@std/collections@^1.0.11",
4346
"@std/http": "jsr:@std/http@^1.0.15",
4447
"fresh": "jsr:@fresh/core@^2.0.0-alpha.26",
4548
"preact": "npm:preact@^10.25.1",

deno.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/error.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,69 @@
11
import { STATUS_TEXT } from "@std/http/status";
22

3+
/**
4+
* Error that's thrown when a request fails. Correlates to a
5+
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status | HTTP status}.
6+
*
7+
* @property status The HTTP status code.
8+
*
9+
* @example Basic usage
10+
* ```ts
11+
* import { App, HttpError } from "fresh";
12+
* import { expect } from "@std/expect";
13+
*
14+
* const app = new App()
15+
* .get("/", () => new Response("ok"))
16+
* .get("/not-found", () => {
17+
* throw new HttpError(404, "Nothing here");
18+
* });
19+
*
20+
* const handler = await app.handler();
21+
*
22+
* try {
23+
* await handler(new Request("http://localhost/not-found"))
24+
* } catch (error) {
25+
* expect(error).toBeInstanceOf(HttpError);
26+
* expect(error.status).toBe(404);
27+
* expect(error.message).toBe("Nothing here");
28+
* }
29+
* ```
30+
*/
331
export class HttpError extends Error {
32+
/**
33+
* The HTTP status code.
34+
*
35+
* @example Basic usage
36+
* ```ts
37+
* import { App, HttpError } from "fresh";
38+
* import { expect } from "@std/expect";
39+
*
40+
* const app = new App()
41+
* .get("/", () => new Response("ok"))
42+
* .get("/not-found", () => {
43+
* throw new HttpError(404, "Nothing here");
44+
* });
45+
*
46+
* const handler = await app.handler();
47+
*
48+
* try {
49+
* await handler(new Request("http://localhost/not-found"))
50+
* } catch (error) {
51+
* expect(error).toBeInstanceOf(HttpError);
52+
* expect(error.status).toBe(404);
53+
* expect(error.message).toBe("Nothing here");
54+
* }
55+
* ```
56+
*/
457
status: number;
558

59+
/**
60+
* Constructs a new instance.
61+
*
62+
* @param status The HTTP status code.
63+
* @param message The error message. Defaults to the status text of the given
64+
* status code.
65+
* @param options Optional error options.
66+
*/
667
constructor(
768
status: keyof typeof STATUS_TEXT,
869
message: string = STATUS_TEXT[status],

tools/check_docs.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { checkDocs } from "https://github.com/denoland/std/raw/refs/heads/main/_tools/check_docs.ts";
2+
3+
await checkDocs([
4+
import.meta.resolve("../src/error.ts"),
5+
]);

0 commit comments

Comments
 (0)