diff --git a/index.ts b/index.ts index c4b1d16..20a990d 100644 --- a/index.ts +++ b/index.ts @@ -3,6 +3,7 @@ import { GithubAPIClient } from "./src/github_api_client.ts"; import { Card } from "./src/card.ts"; import { CONSTANTS, parseParams } from "./src/utils.ts"; import { COLORS, Theme } from "./src/theme.ts"; +import { Error400 } from './src/error_page.ts'; import "https://deno.land/x/dotenv@v0.5.0/load.ts"; const client = new GithubAPIClient(); @@ -41,10 +42,14 @@ export default async (req: ServerRequest) => { ).map((r) => r.trim()); if (username === null) { + const [base] = req.url.split("?"); + const error = new Error400(`
username is a required query parameterThe URL should look like ${base}?username=USERNAME, where
+USERNAME is your GitHub username.`);
req.respond(
{
- body: "Can not find a query parameter: username",
- status: 404,
+ body: error.render(),
+ status: error.status,
headers: new Headers({ "Content-Type": "text" }),
},
);
diff --git a/src/error_page.ts b/src/error_page.ts
new file mode 100644
index 0000000..862f6a7
--- /dev/null
+++ b/src/error_page.ts
@@ -0,0 +1,11 @@
+abstract class BaseError {
+ readonly status!: number;
+ constructor(readonly content?: string) {}
+ render(): string {
+ return `