diff --git a/packages/nestjs-org/package.json b/packages/nestjs-org/package.json index c74893be7..c615c0747 100644 --- a/packages/nestjs-org/package.json +++ b/packages/nestjs-org/package.json @@ -16,6 +16,7 @@ "@concepta/nestjs-common": "^5.0.0-alpha.4", "@concepta/nestjs-crud": "^5.0.0-alpha.4", "@concepta/nestjs-event": "^5.0.0-alpha.4", + "@concepta/nestjs-exception": "^5.0.0-alpha.4", "@concepta/nestjs-typeorm-ext": "^5.0.0-alpha.4", "@concepta/ts-common": "^5.0.0-alpha.4", "@concepta/ts-core": "^5.0.0-alpha.4", diff --git a/packages/nestjs-org/src/exceptions/org-member.exception.ts b/packages/nestjs-org/src/exceptions/org-member.exception.ts index 55f9bbf0a..1aeb3fa5d 100644 --- a/packages/nestjs-org/src/exceptions/org-member.exception.ts +++ b/packages/nestjs-org/src/exceptions/org-member.exception.ts @@ -1,9 +1,10 @@ -import { ExceptionInterface } from '@concepta/ts-core'; - -export class OrgMemberException extends Error implements ExceptionInterface { - errorCode = 'ORG_MEMBER_ERROR'; +import { RuntimeException } from '@concepta/nestjs-exception'; +export class OrgMemberException extends RuntimeException { constructor(message: string) { - super(message); + super({ + message, + }); + this.errorCode = 'ORG_MEMBER_ERROR'; } } diff --git a/packages/nestjs-org/src/exceptions/org-not-found.exception.ts b/packages/nestjs-org/src/exceptions/org-not-found.exception.ts index 5687efb71..9c7f8e747 100644 --- a/packages/nestjs-org/src/exceptions/org-not-found.exception.ts +++ b/packages/nestjs-org/src/exceptions/org-not-found.exception.ts @@ -1,9 +1,14 @@ -import { ExceptionInterface } from '@concepta/ts-core'; +import { + RuntimeException, + RuntimeExceptionOptions, +} from '@concepta/nestjs-exception'; -export class OrgNotFoundException extends Error implements ExceptionInterface { - errorCode = 'ORG_NOT_FOUND_ERROR'; - - constructor(message = 'The org was not found') { - super(message); +export class OrgNotFoundException extends RuntimeException { + constructor(options?: RuntimeExceptionOptions) { + super({ + message: 'The org was not found', + ...options, + }); + this.errorCode = 'ORG_NOT_FOUND_ERROR'; } } diff --git a/packages/nestjs-user/package.json b/packages/nestjs-user/package.json index 851fef155..91bad23bb 100644 --- a/packages/nestjs-user/package.json +++ b/packages/nestjs-user/package.json @@ -16,6 +16,7 @@ "@concepta/nestjs-common": "^5.0.0-alpha.4", "@concepta/nestjs-crud": "^5.0.0-alpha.4", "@concepta/nestjs-event": "^5.0.0-alpha.4", + "@concepta/nestjs-exception": "^5.0.0-alpha.4", "@concepta/nestjs-password": "^5.0.0-alpha.4", "@concepta/nestjs-typeorm-ext": "^5.0.0-alpha.4", "@concepta/ts-common": "^5.0.0-alpha.4", diff --git a/packages/nestjs-user/src/exceptions/user-exception.ts b/packages/nestjs-user/src/exceptions/user-exception.ts index a533a6552..b10324373 100644 --- a/packages/nestjs-user/src/exceptions/user-exception.ts +++ b/packages/nestjs-user/src/exceptions/user-exception.ts @@ -1,21 +1,14 @@ -import { ExceptionInterface, mapNonErrorToException } from '@concepta/ts-core'; - +import { mapNonErrorToException } from '@concepta/ts-core'; +import { RuntimeException } from '@concepta/nestjs-exception'; /** * Generic user exception. */ -export class UserException extends Error implements ExceptionInterface { - errorCode = 'USER_ERROR'; - - context: { - message: string; - originalError: Error; - }; - +export class UserException extends RuntimeException { constructor(message: string, originalError?: unknown) { - super(message); - this.context = { + super({ message, originalError: mapNonErrorToException(originalError), - }; + }); + this.errorCode = 'USER_ERROR'; } } diff --git a/packages/nestjs-user/src/exceptions/user-not-found-exception.ts b/packages/nestjs-user/src/exceptions/user-not-found-exception.ts index 5f6b9a789..c857d2300 100644 --- a/packages/nestjs-user/src/exceptions/user-not-found-exception.ts +++ b/packages/nestjs-user/src/exceptions/user-not-found-exception.ts @@ -1,9 +1,16 @@ -import { ExceptionInterface } from '@concepta/ts-core'; +import { + RuntimeException, + RuntimeExceptionOptions, +} from '@concepta/nestjs-exception'; +import { HttpStatus } from '@nestjs/common'; -export class UserNotFoundException extends Error implements ExceptionInterface { - errorCode = 'USER_NOT_FOUND_ERROR'; - - constructor(message = 'The user was not found') { - super(message); +export class UserNotFoundException extends RuntimeException { + constructor(options?: RuntimeExceptionOptions) { + super({ + message: 'The user was not found', + httpStatus: HttpStatus.NOT_FOUND, + ...options, + }); + this.errorCode = 'USER_NOT_FOUND_ERROR'; } } diff --git a/packages/nestjs-user/src/services/user-password.service.ts b/packages/nestjs-user/src/services/user-password.service.ts index b90c7a050..d143c8a1c 100644 --- a/packages/nestjs-user/src/services/user-password.service.ts +++ b/packages/nestjs-user/src/services/user-password.service.ts @@ -132,9 +132,9 @@ export class UserPasswordService implements UserPasswordServiceInterface { } // throw an exception by default - throw new UserNotFoundException( - 'Impossible to update password if user is not found', - ); + throw new UserNotFoundException({ + message: 'Impossible to update password if user is not found', + }); } protected async validateCurrent(