Refactored all error messages, throws and tests. Added more throwing points and fixed others

This commit is contained in:
Alexander Cerutti
2021-10-15 01:02:17 +02:00
parent 52fafd4405
commit 907bb07912
6 changed files with 193 additions and 157 deletions

View File

@@ -1,6 +1,6 @@
import * as path from "path";
import * as Utils from "./utils";
import formatMessage, { ERROR } from "./messages";
import formatMessage, * as Messages from "./messages";
import { promises as fs } from "fs";
/**
@@ -54,12 +54,15 @@ export default async function getModelFolderContents(
if (err.syscall === "open") {
// file opening failed
throw new Error(
formatMessage(ERROR.MODELF_NOT_FOUND, err.path),
formatMessage(
Messages.MODELS.FILE_NO_OPEN,
JSON.stringify(err),
),
);
} else if (err.syscall === "scandir") {
// directory reading failed
throw new Error(
formatMessage(ERROR.MODELF_FILE_NOT_FOUND, err.path),
formatMessage(Messages.MODELS.DIR_NOT_FOUND, err.path),
);
}
}