mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-07-06 05:38:09 +02:00
fix: handle not found repository
This commit is contained in:
@@ -147,13 +147,21 @@ export async function getRepositoryFromGitHub(opt: {
|
|||||||
accessToken: string;
|
accessToken: string;
|
||||||
}) {
|
}) {
|
||||||
const octokit = new Octokit({ auth: opt.accessToken });
|
const octokit = new Octokit({ auth: opt.accessToken });
|
||||||
const r = (
|
let r;
|
||||||
await octokit.repos.get({
|
try {
|
||||||
owner: opt.owner,
|
r = (
|
||||||
repo: opt.repo,
|
await octokit.repos.get({
|
||||||
})
|
owner: opt.owner,
|
||||||
).data;
|
repo: opt.repo,
|
||||||
if (!r) throw new AnonymousError("repo_not_found", this);
|
})
|
||||||
|
).data;
|
||||||
|
} catch (error) {
|
||||||
|
if (error.status == 404) {
|
||||||
|
throw new AnonymousError("repo_not_found", {owner: opt.owner, repo: opt.repo});
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
if (!r) throw new AnonymousError("repo_not_found", {owner: opt.owner, repo: opt.repo});
|
||||||
let model = await RepositoryModel.findOne({ externalId: "gh_" + r.id });
|
let model = await RepositoryModel.findOne({ externalId: "gh_" + r.id });
|
||||||
if (!model) {
|
if (!model) {
|
||||||
model = new RepositoryModel({ externalId: "gh_" + r.id });
|
model = new RepositoryModel({ externalId: "gh_" + r.id });
|
||||||
|
|||||||
Reference in New Issue
Block a user