diff --git a/.husky/pre-push b/.husky/pre-push index f138ac76..390f5f5e 100644 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1 +1 @@ -bun nx run-many --target=lint,test:unit +pnpm nx run-many --target=lint,test:unit diff --git a/packages/common/src/exception/abstracts/exception.abstract.ts b/packages/common/src/exception/abstracts/exception.abstract.ts new file mode 100644 index 00000000..0857c571 --- /dev/null +++ b/packages/common/src/exception/abstracts/exception.abstract.ts @@ -0,0 +1,11 @@ +import type { INfException } from "../interfaces/exception.type"; + +export abstract class NfException extends Error implements INfException { + abstract get code(): number; + + protected constructor(message?: string) { + super( + message ? `[NANOFORGE] ${message}` : "[NANOFORGE] An error occurred (Unknown exception).", + ); + } +} diff --git a/packages/common/src/exception/exceptions/not-found.exception.ts b/packages/common/src/exception/exceptions/not-found.exception.ts new file mode 100644 index 00000000..220be27c --- /dev/null +++ b/packages/common/src/exception/exceptions/not-found.exception.ts @@ -0,0 +1,11 @@ +import { NfException } from "../abstracts/exception.abstract"; + +export class NfNotFound extends NfException { + get code(): number { + return 404; + } + + constructor(item: string, type?: string) { + super(`${type ? `${type} - ` : ""}${item} not found.`); + } +} diff --git a/packages/common/src/exception/index.ts b/packages/common/src/exception/index.ts new file mode 100644 index 00000000..851ccaf0 --- /dev/null +++ b/packages/common/src/exception/index.ts @@ -0,0 +1 @@ +export { NfNotFound } from "./exceptions/not-found.exception"; diff --git a/packages/common/src/exceptions/nfException.ts b/packages/common/src/exception/interfaces/exception.type.ts similarity index 100% rename from packages/common/src/exceptions/nfException.ts rename to packages/common/src/exception/interfaces/exception.type.ts diff --git a/packages/common/src/exceptions/index.ts b/packages/common/src/exceptions/index.ts deleted file mode 100644 index 459344b1..00000000 --- a/packages/common/src/exceptions/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { NfNotFound } from "./notFound"; diff --git a/packages/common/src/exceptions/notFound.ts b/packages/common/src/exceptions/notFound.ts deleted file mode 100644 index e52828c7..00000000 --- a/packages/common/src/exceptions/notFound.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { type INfException } from "./nfException"; - -export class NfNotFound implements INfException { - get code(): number { - return 404; - } - - message: string; - name: string; - stack?: string | undefined; - cause?: unknown; - - constructor(item: string) { - this.message = `${item} not found.`; - } -} diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index 2b868c17..c88c5209 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -1,4 +1,4 @@ export * from "./context"; export * from "./library"; export * from "./options"; -export * from "./exceptions"; +export * from "./exception";