Skip to content

Commit

Permalink
feat: bring more exceptions up to runtime exception standards
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMaz committed Oct 18, 2024
1 parent 46eb8f8 commit 17a7f76
Show file tree
Hide file tree
Showing 33 changed files with 226 additions and 121 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class AuthAppleDecodeException extends RuntimeException {
constructor(message = 'Apple token was not able to be decoded.') {
constructor(options?: RuntimeExceptionOptions) {
super({
safeMessage: message,
safeMessage: 'Apple token was not able to be decoded.',
...options,
});

this.errorCode = 'AUTH_APPLE_DECODE_ERROR';
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class AuthAppleEmailNotVerifiedException extends RuntimeException {
constructor(message = 'Apple email not is verified.') {
constructor(options?: RuntimeExceptionOptions) {
super({
safeMessage: message,
safeMessage: 'Apple email not is verified.',
...options,
});

this.errorCode = 'AUTH_APPLE_EMAIL_NOT_VERIFIED';
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class AuthAppleInvalidAudienceException extends RuntimeException {
constructor(message = 'Apple audience is not valid.') {
constructor(options?: RuntimeExceptionOptions) {
super({
safeMessage: message,
safeMessage: 'Apple audience is not valid.',
...options,
});

this.errorCode = 'AUTH_APPLE_INVALID_AUDIENCE';
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class AuthAppleInvalidIssuerException extends RuntimeException {
constructor(message = 'Apple token issuer is not valid.') {
constructor(options?: RuntimeExceptionOptions) {
super({
safeMessage: message,
safeMessage: 'Apple token issuer is not valid.',
...options,
});

this.errorCode = 'AUTH_APPLE_INVALID_ISSUER';
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class AuthAppleMissingEmailException extends RuntimeException {
constructor(message = 'Apple did not return an email address for the user.') {
constructor(options?: RuntimeExceptionOptions) {
super({
safeMessage: message,
safeMessage: 'Apple did not return an email address for the user.',
...options,
});

this.errorCode = 'AUTH_APPLE_MISSING_PROFILE_EMAIL_ERROR';
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class AuthAppleMissingIdException extends RuntimeException {
constructor(message = 'Apple did not return an id for the user.') {
constructor(options?: RuntimeExceptionOptions) {
super({
safeMessage: message,
safeMessage: 'Apple did not return an id for the user.',
...options,
});

this.errorCode = 'AUTH_APPLE_MISSING_PROFILE_ID_ERROR';
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class AuthApplePublicKeyException extends RuntimeException {
constructor(message = 'Apple public key was not able to be retrieved.') {
constructor(options?: RuntimeExceptionOptions) {
super({
safeMessage: message,
safeMessage: 'Apple public key was not able to be retrieved.',
...options,
});

this.errorCode = 'AUTH_APPLE_PUBLIC_KEY_ERROR';
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class AuthAppleTokenExpiredException extends RuntimeException {
constructor(message = 'Apple oauth token has expired.') {
constructor(options?: RuntimeExceptionOptions) {
super({
safeMessage: message,
safeMessage: 'Apple oauth token has expired.',
...options,
});

this.errorCode = 'AUTH_APPLE_OAUTH_TOKEN_EXPIRED';
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class AuthGithubMissingEmailException extends RuntimeException {
constructor(
message = 'GitHub did not return an email address for the user.',
) {
constructor(options?: RuntimeExceptionOptions) {
super({
safeMessage: message,
safeMessage: 'GitHub did not return an email address for the user.',
...options,
});

this.errorCode = 'AUTH_GITHUB_MISSING_PROFILE_EMAIL_ERROR';
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class AuthGithubMissingIdException extends RuntimeException {
constructor(message = 'GitHub did not return an id for the user.') {
constructor(options?: RuntimeExceptionOptions) {
super({
safeMessage: message,
safeMessage: 'GitHub did not return an id for the user.',
...options,
});

this.errorCode = 'AUTH_GITHUB_MISSING_PROFILE_ID_ERROR';
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class AuthGoogleMissingEmailException extends RuntimeException {
constructor(
message = 'Google did not return an email address for the user.',
) {
constructor(options?: RuntimeExceptionOptions) {
super({
safeMessage: message,
safeMessage: 'Google did not return an email address for the user.',
...options,
});

this.errorCode = 'AUTH_GOOGLE_MISSING_PROFILE_EMAIL_ERROR';
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class AuthGoogleMissingIdException extends RuntimeException {
constructor(message = 'Google did not return an id for the user.') {
constructor(options?: RuntimeExceptionOptions) {
super({
safeMessage: message,
safeMessage: 'Google did not return an id for the user.',
...options,
});

this.errorCode = 'AUTH_GOOGLE_MISSING_PROFILE_ID_ERROR';
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ReferenceIdInterface } from '@concepta/ts-core';
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';
import { HttpStatus } from '@nestjs/common';

export class FederatedUserLookupException extends RuntimeException {
Expand All @@ -11,14 +14,17 @@ export class FederatedUserLookupException extends RuntimeException {
constructor(
entityName: string,
user: ReferenceIdInterface,
message = 'Error while trying find user %s',
options?: RuntimeExceptionOptions,
) {
super({
message,
message: 'Error while trying find user %s',
messageParams: [user.id],
httpStatus: HttpStatus.NOT_FOUND,
...options,
});

this.errorCode = 'FEDERATED_USER_LOOKUP_ERROR';

this.context = {
...super.context,
entityName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';
import { HttpStatus } from '@nestjs/common';
export class FederatedUserRelationshipException extends RuntimeException {
context: RuntimeException['context'] & {
federatedId: string;
};

constructor(
federatedId: string,
message = 'Error while trying to load user relationship from federated %s',
) {
constructor(federatedId: string, options?: RuntimeExceptionOptions) {
super({
message,
message: 'Error while trying to load user relationship from federated %s',
messageParams: [federatedId],
httpStatus: HttpStatus.NOT_FOUND,
...options,
});

this.errorCode = 'FEDERATED_USER_RELATIONSHIP_ERROR';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ export class FederatedOAuthService implements FederatedOAuthServiceInterface {
);
} else {
if (!federated.user?.id) {
throw new FederatedUserRelationshipException(
this.constructor.name,
federated.id,
);
throw new FederatedUserRelationshipException(federated.id);
}

const user = await this.userLookupService.byId(
Expand Down
12 changes: 7 additions & 5 deletions packages/nestjs-file/src/exceptions/file-duplicated.exception.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { HttpStatus } from '@nestjs/common';
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class FileDuplicateEntryException extends RuntimeException {
context: RuntimeException['context'] & {
Expand All @@ -10,14 +13,13 @@ export class FileDuplicateEntryException extends RuntimeException {
constructor(
serviceKey: string,
fileName: string,
originalError?: unknown,
message = 'Duplicate entry detected for service %s with file %s',
options?: RuntimeExceptionOptions,
) {
super({
message,
message: 'Duplicate entry detected for service %s with file %s',
messageParams: [serviceKey, fileName],
httpStatus: HttpStatus.CONFLICT,
originalError,
...options,
});

this.errorCode = 'FILE_DUPLICATE_ENTRY_ERROR';
Expand Down
10 changes: 7 additions & 3 deletions packages/nestjs-file/src/exceptions/file-id-missing.exception.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { HttpStatus } from '@nestjs/common';
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class FileIdMissingException extends RuntimeException {
constructor(message = 'File id is missing.') {
constructor(options?: RuntimeExceptionOptions) {
super({
message,
message: 'File id is missing.',
httpStatus: HttpStatus.BAD_REQUEST,
...options,
});

this.errorCode = 'FILE_ID_MISSING_ERROR';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { HttpStatus } from '@nestjs/common';
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class FileStorageServiceNotFoundException extends RuntimeException {
context: RuntimeException['context'] & {
storageServiceName: string;
};

constructor(
assignmentName: string,
message = 'Storage Service %s was not registered to be used.',
) {
constructor(assignmentName: string, options?: RuntimeExceptionOptions) {
super({
message,
message: 'Storage Service %s was not registered to be used.',
messageParams: [assignmentName],
httpStatus: HttpStatus.NOT_FOUND,
...options,
});

this.errorCode = 'FILE_STORAGE_SERVICE_NOT_FOUND_ERROR';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ describe('loggerSentryTransport', () => {
httpStatus: HttpStatus.BAD_REQUEST,
...options,
});

this.errorCode = 'INVALID_LOGIN_DATA_ERROR';
}
}
Expand Down
10 changes: 2 additions & 8 deletions packages/nestjs-org/src/exceptions/org-member.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@ import {
} from '@concepta/nestjs-exception';

export class OrgMemberException extends RuntimeException {
constructor(
message: string,
options?: Omit<RuntimeExceptionOptions, 'message'>,
) {
super({
message,
...options,
});
constructor(options?: RuntimeExceptionOptions) {
super(options);
this.errorCode = 'ORG_MEMBER_ERROR';
}
}
Loading

0 comments on commit 17a7f76

Please sign in to comment.