chore: add doc checker (#2877)
First steps towards #2876 Depends on https://github.com/denoland/std/pull/6632
This commit is contained in:
@@ -8,88 +8,88 @@ const css = (arr: TemplateStringsArray, ...exts: never[]) => {
|
||||
|
||||
export const errorCss = css`
|
||||
:root {
|
||||
--bg: #fff;
|
||||
--bg-code-frame: rgb(255, 0, 32, 0.1);
|
||||
--bg-active-line: #fbcecc;
|
||||
--text: #222;
|
||||
--text2: #444;
|
||||
--title: #e84644;
|
||||
--code: #333;
|
||||
font-family: sans-serif;
|
||||
line-height: 1.4;
|
||||
color: var(--text);
|
||||
background: var(--bg);
|
||||
}
|
||||
--bg: #fff;
|
||||
--bg-code-frame: rgb(255, 0, 32, 0.1);
|
||||
--bg-active-line: #fbcecc;
|
||||
--text: #222;
|
||||
--text2: #444;
|
||||
--title: #e84644;
|
||||
--code: #333;
|
||||
font-family: sans-serif;
|
||||
line-height: 1.4;
|
||||
color: var(--text);
|
||||
background: var(--bg);
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--bg-code-frame: rgba(251, 93, 113, 0.2);
|
||||
--bg-active-line: #4f1919;
|
||||
--bg: #353535;
|
||||
--text: #f7f7f7;
|
||||
--text2: #ddd;
|
||||
--code: #fdd1d1;
|
||||
}
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--bg-code-frame: rgba(251, 93, 113, 0.2);
|
||||
--bg-active-line: #4f1919;
|
||||
--bg: #353535;
|
||||
--text: #f7f7f7;
|
||||
--text2: #ddd;
|
||||
--code: #fdd1d1;
|
||||
}
|
||||
}
|
||||
|
||||
.inner {
|
||||
max-width: 48rem;
|
||||
padding: 4rem 1rem;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.inner {
|
||||
max-width: 48rem;
|
||||
padding: 4rem 1rem;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.title {
|
||||
color: var(--title);
|
||||
font-weight: normal;
|
||||
font-size: 1.5rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.title {
|
||||
color: var(--title);
|
||||
font-weight: normal;
|
||||
font-size: 1.5rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.code-frame {
|
||||
overflow: auto;
|
||||
padding: 0.5rem;
|
||||
margin-bottom: 0.5rem;
|
||||
background: var(--bg-code-frame);
|
||||
color: var(--code);
|
||||
}
|
||||
.line {
|
||||
padding: 0.25rem 0.5rem;
|
||||
}
|
||||
.active-line {
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
background: var(--bg-active-line);
|
||||
}
|
||||
.code-frame {
|
||||
overflow: auto;
|
||||
padding: 0.5rem;
|
||||
margin-bottom: 0.5rem;
|
||||
background: var(--bg-code-frame);
|
||||
color: var(--code);
|
||||
}
|
||||
.line {
|
||||
padding: 0.25rem 0.5rem;
|
||||
}
|
||||
.active-line {
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
background: var(--bg-active-line);
|
||||
}
|
||||
|
||||
.stack {
|
||||
overflow-x: auto;
|
||||
}
|
||||
.stack {
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
position: absolute;
|
||||
top: 1rem;
|
||||
right: 1rem;
|
||||
color: var(--title);
|
||||
display: block;
|
||||
width: 3rem;
|
||||
height: 3rem;
|
||||
background: none;
|
||||
border: none;
|
||||
transform: translate3d(0, 0, 0);
|
||||
}
|
||||
.close-btn:active {
|
||||
transform: translate3d(0, 2px, 0);
|
||||
}
|
||||
.close-btn:hover {
|
||||
cursor: pointer;
|
||||
filter: drop-shadow(0 0 0.75rem crimson);
|
||||
}
|
||||
.close-btn {
|
||||
position: absolute;
|
||||
top: 1rem;
|
||||
right: 1rem;
|
||||
color: var(--title);
|
||||
display: block;
|
||||
width: 3rem;
|
||||
height: 3rem;
|
||||
background: none;
|
||||
border: none;
|
||||
transform: translate3d(0, 0, 0);
|
||||
}
|
||||
.close-btn:active {
|
||||
transform: translate3d(0, 2px, 0);
|
||||
}
|
||||
.close-btn:hover {
|
||||
cursor: pointer;
|
||||
filter: drop-shadow(0 0 0.75rem crimson);
|
||||
}
|
||||
`;
|
||||
|
||||
function CodeFrame(props: { codeFrame: string }) {
|
||||
|
||||
@@ -1,8 +1,69 @@
|
||||
import { STATUS_TEXT } from "@std/http/status";
|
||||
|
||||
/**
|
||||
* Error that's thrown when a request fails. Correlates to a
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status | HTTP status}.
|
||||
*
|
||||
* @property status The HTTP status code.
|
||||
*
|
||||
* @example Basic usage
|
||||
* ```ts
|
||||
* import { App, HttpError } from "fresh";
|
||||
* import { expect } from "@std/expect";
|
||||
*
|
||||
* const app = new App()
|
||||
* .get("/", () => new Response("ok"))
|
||||
* .get("/not-found", () => {
|
||||
* throw new HttpError(404, "Nothing here");
|
||||
* });
|
||||
*
|
||||
* const handler = await app.handler();
|
||||
*
|
||||
* try {
|
||||
* await handler(new Request("http://localhost/not-found"))
|
||||
* } catch (error) {
|
||||
* expect(error).toBeInstanceOf(HttpError);
|
||||
* expect(error.status).toBe(404);
|
||||
* expect(error.message).toBe("Nothing here");
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export class HttpError extends Error {
|
||||
/**
|
||||
* The HTTP status code.
|
||||
*
|
||||
* @example Basic usage
|
||||
* ```ts
|
||||
* import { App, HttpError } from "fresh";
|
||||
* import { expect } from "@std/expect";
|
||||
*
|
||||
* const app = new App()
|
||||
* .get("/", () => new Response("ok"))
|
||||
* .get("/not-found", () => {
|
||||
* throw new HttpError(404, "Nothing here");
|
||||
* });
|
||||
*
|
||||
* const handler = await app.handler();
|
||||
*
|
||||
* try {
|
||||
* await handler(new Request("http://localhost/not-found"))
|
||||
* } catch (error) {
|
||||
* expect(error).toBeInstanceOf(HttpError);
|
||||
* expect(error.status).toBe(404);
|
||||
* expect(error.message).toBe("Nothing here");
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
status: number;
|
||||
|
||||
/**
|
||||
* Constructs a new instance.
|
||||
*
|
||||
* @param status The HTTP status code.
|
||||
* @param message The error message. Defaults to the status text of the given
|
||||
* status code.
|
||||
* @param options Optional error options.
|
||||
*/
|
||||
constructor(
|
||||
status: keyof typeof STATUS_TEXT,
|
||||
message: string = STATUS_TEXT[status],
|
||||
|
||||
Reference in New Issue
Block a user