Browse Source

Support to 404 error

pr-125
ryo-ma 8 months ago
parent
commit
3544e23c13
  1. 9
      index.ts
  2. 5
      src/error_page.ts
  3. 3
      src/github_api_client.ts

9
index.ts

@ -2,7 +2,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 { Error400, Error404 } from "./src/error_page.ts";
import "https://deno.land/x/[email protected]/load.ts";
const client = new GithubAPIClient();
@ -58,10 +58,13 @@ export default async (req: Request) => {
const token = Deno.env.get("GITHUB_TOKEN");
const userInfo = await client.requestUserInfo(token, username);
if (userInfo === null) {
const error = new Error404(
"Can not find a user with username: " + username,
);
return new Response(
"Can not find a user with userID: " + username,
error.render(),
{
status: 404,
status: error.status,
headers: new Headers({ "Content-Type": "text" }),
},
);

5
src/error_page.ts

@ -13,3 +13,8 @@ export class Error400 extends BaseError {
readonly status = 400;
readonly message = "Bad Reuquest";
}
export class Error404 extends BaseError {
readonly status = 404;
readonly message = "Not Found";
}

3
src/github_api_client.ts

@ -21,6 +21,9 @@ export class GithubAPIClient {
this.requestUserPullRequest(token, username),
this.requestUserRepository(token, username),
]);
if (results.some((r) => r == null)) {
return null;
}
return new UserInfo(results[0]!, results[1]!, results[2]!, results[3]!);
}
private async requestUserActivity(

Loading…
Cancel
Save