From ba9ec70c7740a805210a8def3e7611c026342e7a Mon Sep 17 00:00:00 2001 From: Max P Date: Thu, 22 Aug 2024 20:34:21 +0200 Subject: [PATCH] Add InjectorError and NoInstantiationMethodError classes - Added `InjectorError` class for handling injector errors - Added `NoInstantiationMethodError` class for missing instantiation methods - Both classes extend `TSinjexError` and provide detailed error messages --- src/interfaces/Exceptions.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/interfaces/Exceptions.ts b/src/interfaces/Exceptions.ts index e638422..efe6d30 100644 --- a/src/interfaces/Exceptions.ts +++ b/src/interfaces/Exceptions.ts @@ -29,3 +29,39 @@ export class DependencyResolutionError extends TSinjexError { this.name = 'TSinjexResolutionError'; } } + +/** + * Error class for Injector errors in {@link ITSinjex}. + * @see {@link ITSinjex.inject} + */ +export class InjectorError extends TSinjexError { + /** + * Creates a new instance of {@link InjectorError} + * @param message **The error message** + * @param identifier **The identifier of the dependency** + * @param originalError **The original error that caused the injection error** + */ + constructor(identifier: Identifier, originalError?: Error) { + super( + `Error injecting dependency ${identifier.toString()} with error: "${originalError}"`, + ); + this.name = 'TSinjexInjectorError'; + } +} + +/** + * Error class for missing instantiation methods in {@link ITSinjex}. + * @see {@link ITSinjex.inject} + */ +export class NoInstantiationMethodError extends TSinjexError { + /** + * Creates a new instance of {@link NoInstantiationMethodError} + * @param identifier **The identifier of the dependency** + */ + constructor(identifier: Identifier) { + super( + `No instantiation method found for dependency ${identifier.toString()}.`, + ); + this.name = 'TSinjexNoInstantiationMethodError'; + } +}