diff options
author | HampusM <hampus@hampusmat.com> | 2021-07-21 22:00:04 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-07-21 22:00:04 +0200 |
commit | 7b9fca8d0061cf5e5af08cba98e9d5b6dbbed8ec (patch) | |
tree | 2a75dfaaa495c90e5519012e2c8e20ab0bd7ac4e /packages/server/src/git/tree.ts | |
parent | c0eb6635964de276b44851df67fb857ae94dc401 (diff) |
Began with better backend error handling & cleaned up the backend
Diffstat (limited to 'packages/server/src/git/tree.ts')
-rw-r--r-- | packages/server/src/git/tree.ts | 16 |
1 files changed, 9 insertions, 7 deletions
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<Blob | Tree | null> { + public async find(path: string): Promise<Blob | Tree> { 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<Tree> { + const master_commit = await owner.masterCommit(); + return master_commit.tree(); + } }
\ No newline at end of file |