Start handling bad requests on client-side rather than Netlify-side (#4)
Too much can go wrong on the side of Netlify, so it should throw on purpose if anything goes bad so the client can `catch` that
This commit is contained in:
parent
3072c8c88d
commit
b4af91405d
4 changed files with 74 additions and 48 deletions
|
@ -4,33 +4,19 @@ import {type GithubInfo} from "../../src/components/Info/Git.js";
|
|||
|
||||
const handler: Handler = async () => {
|
||||
const octokit = new Octokit({auth: process.env.API_GITHUB});
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
const github = await octokit.rest.activity.listEventsForAuthenticatedUser({username: "TTTaevas"});
|
||||
|
||||
if (github.status !== 200) {
|
||||
return {
|
||||
statusCode: 404,
|
||||
body: "",
|
||||
};
|
||||
}
|
||||
|
||||
const publicPush = github.data.find((e) => e.type === "PushEvent" && e.public);
|
||||
const privatePush = github.data.find((e) => e.type === "PushEvent" && !e.public);
|
||||
if (!publicPush || !privatePush) {
|
||||
return {
|
||||
statusCode: 404,
|
||||
body: "",
|
||||
};
|
||||
}
|
||||
|
||||
const info: GithubInfo = {
|
||||
public: {
|
||||
public: publicPush ? {
|
||||
repo: publicPush.repo.name,
|
||||
date: publicPush.created_at ? publicPush.created_at.substring(0, publicPush.created_at.indexOf("T")) : "",
|
||||
},
|
||||
private: {
|
||||
} : undefined,
|
||||
private: privatePush ? {
|
||||
date: privatePush.created_at ? privatePush.created_at.substring(0, privatePush.created_at.indexOf("T")) : "",
|
||||
},
|
||||
} : undefined,
|
||||
};
|
||||
|
||||
return {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue