From 094de489fcbcbe21fdd6ab89deae09af625a7f7b Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 2 Jun 2021 20:11:59 +0200 Subject: The tree route optionally gets path from query param & has error handling --- src/api/v1.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/api/v1.js b/src/api/v1.js index 743be09..25a8019 100644 --- a/src/api/v1.js +++ b/src/api/v1.js @@ -113,8 +113,18 @@ module.exports = function (fastify, opts, done) path: "/tree", handler: async (req, reply) => { - const tree = await git.getTree(opts.config.settings.base_dir, req.params.repo); + const tree_path = (req.query.length !== 0 && req.query.path) ? req.query.path : null; + const tree = await git.getTree(opts.config.settings.base_dir, req.params.repo, tree_path); + + if(tree.error) { + if(tree.error === 404) { + reply.code(404).send({ error: "Path not found" }); + } + else { + reply.code(500).send({ error: "Internal server error" }); + } + } reply.send({ data: tree }); } }); -- cgit v1.2.3-18-g5258