mirror of
https://github.com/reiyua/github-profile-trophy-reiyua-mirror.git
synced 2026-11-17 06:02:09 +11:00
Support to 404 error
This commit is contained in:
parent
5f08ba0e98
commit
3544e23c13
3 changed files with 14 additions and 3 deletions
9
index.ts
9
index.ts
|
|
@ -2,7 +2,7 @@ import { GithubAPIClient } from "./src/github_api_client.ts";
|
||||||
import { Card } from "./src/card.ts";
|
import { Card } from "./src/card.ts";
|
||||||
import { CONSTANTS, parseParams } from "./src/utils.ts";
|
import { CONSTANTS, parseParams } from "./src/utils.ts";
|
||||||
import { COLORS, Theme } from "./src/theme.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/dotenv@v0.5.0/load.ts";
|
import "https://deno.land/x/dotenv@v0.5.0/load.ts";
|
||||||
|
|
||||||
const client = new GithubAPIClient();
|
const client = new GithubAPIClient();
|
||||||
|
|
@ -58,10 +58,13 @@ export default async (req: Request) => {
|
||||||
const token = Deno.env.get("GITHUB_TOKEN");
|
const token = Deno.env.get("GITHUB_TOKEN");
|
||||||
const userInfo = await client.requestUserInfo(token, username);
|
const userInfo = await client.requestUserInfo(token, username);
|
||||||
if (userInfo === null) {
|
if (userInfo === null) {
|
||||||
|
const error = new Error404(
|
||||||
|
"Can not find a user with username: " + username,
|
||||||
|
);
|
||||||
return new Response(
|
return new Response(
|
||||||
"Can not find a user with userID: " + username,
|
error.render(),
|
||||||
{
|
{
|
||||||
status: 404,
|
status: error.status,
|
||||||
headers: new Headers({ "Content-Type": "text" }),
|
headers: new Headers({ "Content-Type": "text" }),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -13,3 +13,8 @@ export class Error400 extends BaseError {
|
||||||
readonly status = 400;
|
readonly status = 400;
|
||||||
readonly message = "Bad Reuquest";
|
readonly message = "Bad Reuquest";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class Error404 extends BaseError {
|
||||||
|
readonly status = 404;
|
||||||
|
readonly message = "Not Found";
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@ export class GithubAPIClient {
|
||||||
this.requestUserPullRequest(token, username),
|
this.requestUserPullRequest(token, username),
|
||||||
this.requestUserRepository(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]!);
|
return new UserInfo(results[0]!, results[1]!, results[2]!, results[3]!);
|
||||||
}
|
}
|
||||||
private async requestUserActivity(
|
private async requestUserActivity(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue