From 39a24691393620008a2ea0a9743669a4488967e0 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 13 Aug 2021 12:01:29 +0200 Subject: [PATCH] fix: Prevent error when repo is not found --- src/routes/repository-private.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/routes/repository-private.ts b/src/routes/repository-private.ts index 6e05113..a83412c 100644 --- a/src/routes/repository-private.ts +++ b/src/routes/repository-private.ts @@ -15,7 +15,7 @@ const router = express.Router(); // get repository information router.get("/:repoId/", async (req: express.Request, res: express.Response) => { - const repo = await getRepo(req, res, { nocheck: true }); + const repo = await getRepo(req, res, { nocheck: false }); if (!repo) return; try { @@ -75,10 +75,10 @@ router.post("/claim", async (req: express.Request, res: express.Response) => { router.post( "/:repoId/refresh", async (req: express.Request, res: express.Response) => { - const repo = await getRepo(req, res, { nocheck: true }); - if (!repo) return; - try { + const repo = await getRepo(req, res, { nocheck: true }); + if (!repo) throw new Error("repo_not_found"); + const user = await getUser(req); if (repo.owner.username != user.username) { return res.status(401).json({ error: "not_authorized" }); @@ -220,17 +220,17 @@ function updateRepoModel(model: IAnonymizedRepositoryDocument, repoUpdate) { router.post( "/:repoId/", async (req: express.Request, res: express.Response) => { - const repo = await getRepo(req, res, { nocheck: true }); - if (!repo) return; - const user = await getUser(req); - - if (repo.owner.username != user.username) { - return res.status(401).json({ error: "not_authorized" }); - } - - const repoUpdate = req.body; - try { + const repo = await getRepo(req, res, { nocheck: true }); + if (!repo) throw new Error("repo_not_found"); + const user = await getUser(req); + + if (repo.owner.username != user.username) { + return res.status(401).json({ error: "not_authorized" }); + } + + const repoUpdate = req.body; + validateNewRepo(repoUpdate); if (repoUpdate.commit != repo.model.source.commit) {