From 5cde58df10bc138ca7bbd7eab06e6699c2e1b57b Mon Sep 17 00:00:00 2001 From: Exelo Date: Sun, 14 Sep 2025 09:56:08 +0200 Subject: [PATCH 1/2] fix: change exception handling --- .../exception/abstracts/exception.abstract.ts | 9 +++++++++ .../exception/exceptions/not-found.exception.ts | 12 ++++++++++++ packages/common/src/exception/index.ts | 1 + .../interfaces/exception.type.ts} | 0 packages/common/src/exceptions/index.ts | 1 - packages/common/src/exceptions/notFound.ts | 16 ---------------- packages/common/src/index.ts | 2 +- 7 files changed, 23 insertions(+), 18 deletions(-) create mode 100644 packages/common/src/exception/abstracts/exception.abstract.ts create mode 100644 packages/common/src/exception/exceptions/not-found.exception.ts create mode 100644 packages/common/src/exception/index.ts rename packages/common/src/{exceptions/nfException.ts => exception/interfaces/exception.type.ts} (100%) delete mode 100644 packages/common/src/exceptions/index.ts delete mode 100644 packages/common/src/exceptions/notFound.ts 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..d119ab2f --- /dev/null +++ b/packages/common/src/exception/abstracts/exception.abstract.ts @@ -0,0 +1,9 @@ +import {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)."); + } +} \ No newline at end of file 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..8ed21c2f --- /dev/null +++ b/packages/common/src/exception/exceptions/not-found.exception.ts @@ -0,0 +1,12 @@ +import {type INfException} from "../interfaces/exception.type"; +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"; From fef479f8e346e8497a3d0cc5f8231be8077edd21 Mon Sep 17 00:00:00 2001 From: Exelo Date: Mon, 15 Sep 2025 03:46:03 +0200 Subject: [PATCH 2/2] fix(common): update exception imports and adjust formatting in abstract class --- .husky/pre-push | 2 +- .../src/exception/abstracts/exception.abstract.ts | 14 ++++++++------ .../exception/exceptions/not-found.exception.ts | 3 +-- 3 files changed, 10 insertions(+), 9 deletions(-) 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 index d119ab2f..0857c571 100644 --- a/packages/common/src/exception/abstracts/exception.abstract.ts +++ b/packages/common/src/exception/abstracts/exception.abstract.ts @@ -1,9 +1,11 @@ -import {INfException} from "../interfaces/exception.type"; +import type { INfException } from "../interfaces/exception.type"; export abstract class NfException extends Error implements INfException { - abstract get code(): number; + abstract get code(): number; - protected constructor(message?: string) { - super(message ? `[NANOFORGE] ${message}` : "[NANOFORGE] An error occurred (Unknown exception)."); - } -} \ No newline at end of file + 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 index 8ed21c2f..220be27c 100644 --- a/packages/common/src/exception/exceptions/not-found.exception.ts +++ b/packages/common/src/exception/exceptions/not-found.exception.ts @@ -1,5 +1,4 @@ -import {type INfException} from "../interfaces/exception.type"; -import {NfException} from "../abstracts/exception.abstract"; +import { NfException } from "../abstracts/exception.abstract"; export class NfNotFound extends NfException { get code(): number {