Skip to content

Commit

Permalink
chore: upgrade exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
tnramalho committed Oct 16, 2024
1 parent 3493dea commit 3f90429
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 33 deletions.
1 change: 1 addition & 0 deletions packages/nestjs-org/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 6 additions & 5 deletions packages/nestjs-org/src/exceptions/org-member.exception.ts
Original file line number Diff line number Diff line change
@@ -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';
}
}
17 changes: 11 additions & 6 deletions packages/nestjs-org/src/exceptions/org-not-found.exception.ts
Original file line number Diff line number Diff line change
@@ -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';
}
}
1 change: 1 addition & 0 deletions packages/nestjs-user/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 6 additions & 13 deletions packages/nestjs-user/src/exceptions/user-exception.ts
Original file line number Diff line number Diff line change
@@ -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';
}
}
19 changes: 13 additions & 6 deletions packages/nestjs-user/src/exceptions/user-not-found-exception.ts
Original file line number Diff line number Diff line change
@@ -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';
}
}
6 changes: 3 additions & 3 deletions packages/nestjs-user/src/services/user-password.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 3f90429

Please sign in to comment.