From 7b9fca8d0061cf5e5af08cba98e9d5b6dbbed8ec Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 21 Jul 2021 22:00:04 +0200 Subject: Began with better backend error handling & cleaned up the backend --- packages/server/src/git/tree.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'packages/server/src/git/tree.ts') diff --git a/packages/server/src/git/tree.ts b/packages/server/src/git/tree.ts index 8697010..2cec528 100644 --- a/packages/server/src/git/tree.ts +++ b/packages/server/src/git/tree.ts @@ -2,6 +2,7 @@ import { Blob } from "./blob"; import { Tree as NodeGitTree } from "nodegit"; import { Repository } from "./repository"; import { TreeEntry } from "./tree_entry"; +import { createError, TreeError } from "./error"; export class Tree { private _ng_tree: NodeGitTree; @@ -16,18 +17,14 @@ export class Tree { return this._ng_tree.entries().map(entry => new TreeEntry(this._owner, entry)); } - public async find(path: string): Promise { + public async find(path: string): Promise { const entry = await this._ng_tree.getEntry(path).catch(err => { if(err.errno === -3) { - return null; + throw(createError(TreeError, 404, "Path not found")); } - throw(err); + throw(createError(TreeError, 500, "Failed to get tree path")); }); - if(!entry) { - return null; - } - return entry.isBlob() ? new Blob(entry) : new Tree(this._owner, await entry.getTree()); } @@ -36,4 +33,9 @@ export class Tree { .then(() => true) .catch(() => false); } + + public static async ofRepository(owner: Repository): Promise { + const master_commit = await owner.masterCommit(); + return master_commit.tree(); + } } \ No newline at end of file -- cgit v1.2.3-18-g5258