aboutsummaryrefslogtreecommitdiff
path: root/packages/server/src/git/misc.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/server/src/git/misc.ts')
-rw-r--r--packages/server/src/git/misc.ts13
1 files changed, 8 insertions, 5 deletions
diff --git a/packages/server/src/git/misc.ts b/packages/server/src/git/misc.ts
index 637cb8c..bd18322 100644
--- a/packages/server/src/git/misc.ts
+++ b/packages/server/src/git/misc.ts
@@ -1,4 +1,5 @@
import { readFile, readdir } from "fs";
+import { createError, MiscError } from "./error";
export async function findAsync<T>(arr: T[], callback: (t: T) => Promise<boolean>): Promise<T> {
const results = await Promise.all(arr.map(callback));
@@ -6,23 +7,25 @@ export async function findAsync<T>(arr: T[], callback: (t: T) => Promise<boolean
return arr[index];
}
-export function getFile(base_dir: string, repository: string, file: string): Promise<string | null> {
- return new Promise(resolve => {
+export function getFile(base_dir: string, repository: string, file: string): Promise<string> {
+ return new Promise((resolve, reject) => {
readFile(`${base_dir}/${repository}/${file}`, (err, content) => {
if(err) {
- resolve(null);
+ reject(createError(MiscError, 500, "Failed to open repository file " + file));
return;
}
+
resolve(content.toString().replace(/\n/gu, ""));
});
});
}
export function getDirectory(directory: string): Promise<string[]> {
- return new Promise<string[]>(resolve => {
+ return new Promise<string[]>((resolve, reject) => {
readdir(directory, (err, dir_content) => {
if(err) {
- resolve([]);
+ reject(createError(MiscError, 500, "Failed to open directory " + directory));
+ return;
}
resolve(dir_content);