From d333d806c5e58eb84e28d7cba855fa6d0801b167 Mon Sep 17 00:00:00 2001 From: Thiago Ramalho Date: Thu, 17 Oct 2024 12:22:22 -0300 Subject: [PATCH] chore: update mr changes --- .../invalid-credentials.exception.ts | 2 +- .../invalid-login-data.exception.ts | 2 +- .../logger-sentry-extras.interface.ts | 10 +++++++ .../logger-sentry.transport.spec.ts | 2 ++ .../src/transports/logger-sentry.transport.ts | 26 +++++++++++++------ .../src/exceptions/org-member.exception.ts | 11 ++++++-- .../current-password-required.exception.ts | 2 +- 7 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 packages/nestjs-logger-sentry/src/interfaces/logger-sentry-extras.interface.ts diff --git a/packages/nestjs-auth-local/src/exceptions/invalid-credentials.exception.ts b/packages/nestjs-auth-local/src/exceptions/invalid-credentials.exception.ts index be675dfc..31db71c0 100644 --- a/packages/nestjs-auth-local/src/exceptions/invalid-credentials.exception.ts +++ b/packages/nestjs-auth-local/src/exceptions/invalid-credentials.exception.ts @@ -12,6 +12,6 @@ export class InvalidCredentialsException extends RuntimeException { ...options, }); - this.errorCode = 'INVALID_CREDENTIALS_ERROR'; + this.errorCode = 'AUTH_LOCAL_INVALID_CREDENTIALS_ERROR'; } } diff --git a/packages/nestjs-auth-local/src/exceptions/invalid-login-data.exception.ts b/packages/nestjs-auth-local/src/exceptions/invalid-login-data.exception.ts index a287e1c9..f0fcb700 100644 --- a/packages/nestjs-auth-local/src/exceptions/invalid-login-data.exception.ts +++ b/packages/nestjs-auth-local/src/exceptions/invalid-login-data.exception.ts @@ -13,6 +13,6 @@ export class InvalidLoginDataException extends RuntimeException { ...options, }); - this.errorCode = 'INVALID_LOGIN_DATA_ERROR'; + this.errorCode = 'AUTH_LOCAL_INVALID_LOGIN_DATA_ERROR'; } } diff --git a/packages/nestjs-logger-sentry/src/interfaces/logger-sentry-extras.interface.ts b/packages/nestjs-logger-sentry/src/interfaces/logger-sentry-extras.interface.ts new file mode 100644 index 00000000..74a4aa80 --- /dev/null +++ b/packages/nestjs-logger-sentry/src/interfaces/logger-sentry-extras.interface.ts @@ -0,0 +1,10 @@ +import { RuntimeExceptionInterface } from '@concepta/nestjs-exception'; + +export interface LoggerSentryExtrasInterface + extends Partial< + Pick + > { + statusCode?: number; + message?: string | unknown; + originalError?: Error | string; +} diff --git a/packages/nestjs-logger-sentry/src/transports/logger-sentry.transport.spec.ts b/packages/nestjs-logger-sentry/src/transports/logger-sentry.transport.spec.ts index 602d5370..0d6b7050 100644 --- a/packages/nestjs-logger-sentry/src/transports/logger-sentry.transport.spec.ts +++ b/packages/nestjs-logger-sentry/src/transports/logger-sentry.transport.spec.ts @@ -187,7 +187,9 @@ describe('loggerSentryTransport', () => { statusCode: exception?.httpStatus, message: exception?.message, safeMessage: exception?.safeMessage, + originalError: exception?.context?.originalError, context: exception?.context, + }, }); }); diff --git a/packages/nestjs-logger-sentry/src/transports/logger-sentry.transport.ts b/packages/nestjs-logger-sentry/src/transports/logger-sentry.transport.ts index fced23c9..5227162f 100644 --- a/packages/nestjs-logger-sentry/src/transports/logger-sentry.transport.ts +++ b/packages/nestjs-logger-sentry/src/transports/logger-sentry.transport.ts @@ -4,8 +4,8 @@ import { LoggerTransportInterface } from '@concepta/nestjs-logger'; import { LoggerSentrySettingsInterface } from '../interfaces/logger-sentry-settings.interface'; import { LOGGER_SENTRY_MODULE_SETTINGS_TOKEN } from '../config/logger-sentry.config'; import { RuntimeException, mapHttpStatus } from '@concepta/nestjs-exception'; -import { Extras } from '@sentry/types'; import { isObject } from 'class-validator'; +import { LoggerSentryExtrasInterface } from '../interfaces/logger-sentry-extras.interface'; /** * The transport that implements {@link LoggerTransportInterface} @@ -75,8 +75,8 @@ export class LoggerSentryTransport implements LoggerTransportInterface { private getExtras( exception?: Error | string | RuntimeException | HttpException, - ): Extras { - const extras: Extras = {}; + ): LoggerSentryExtrasInterface { + const extras: LoggerSentryExtrasInterface = {}; if (exception instanceof HttpException) { this.handleHttpException(exception, extras); } else if (exception instanceof RuntimeException) { @@ -90,30 +90,40 @@ export class LoggerSentryTransport implements LoggerTransportInterface { return extras; } - private handleHttpException(exception: HttpException, extras: Extras): void { + private handleHttpException( + exception: HttpException, + extras: LoggerSentryExtrasInterface, + ): void { const res = exception.getResponse(); extras.statusCode = exception.getStatus(); - extras.errorCode = mapHttpStatus(extras.statusCode as number); + extras.errorCode = mapHttpStatus(extras.statusCode); extras.message = isObject(res) && 'message' in res ? res.message : res; } private handleRuntimeException( exception: RuntimeException, - extras: Extras, + extras: LoggerSentryExtrasInterface, ): void { extras.errorCode = exception?.errorCode; extras.statusCode = exception?.httpStatus; extras.message = exception?.message; extras.safeMessage = exception?.safeMessage; + extras.originalError = exception?.context?.originalError; extras.context = exception?.context; } - private handleError(exception: Error, extras: Extras): void { + private handleError( + exception: Error, + extras: LoggerSentryExtrasInterface, + ): void { extras.message = exception?.message; extras.originalError = exception?.stack || ''; } - private handleStringException(exception: string, extras: Extras): void { + private handleStringException( + exception: string, + extras: LoggerSentryExtrasInterface, + ): void { extras.message = exception; } } diff --git a/packages/nestjs-org/src/exceptions/org-member.exception.ts b/packages/nestjs-org/src/exceptions/org-member.exception.ts index 1aeb3fa5..d3effe37 100644 --- a/packages/nestjs-org/src/exceptions/org-member.exception.ts +++ b/packages/nestjs-org/src/exceptions/org-member.exception.ts @@ -1,9 +1,16 @@ -import { RuntimeException } from '@concepta/nestjs-exception'; +import { + RuntimeException, + RuntimeExceptionOptions, +} from '@concepta/nestjs-exception'; export class OrgMemberException extends RuntimeException { - constructor(message: string) { + constructor( + message: string, + options?: Omit, + ) { super({ message, + ...options, }); this.errorCode = 'ORG_MEMBER_ERROR'; } diff --git a/packages/nestjs-password/src/exceptions/current-password-required.exception.ts b/packages/nestjs-password/src/exceptions/current-password-required.exception.ts index 7f7eab98..b12e0649 100644 --- a/packages/nestjs-password/src/exceptions/current-password-required.exception.ts +++ b/packages/nestjs-password/src/exceptions/current-password-required.exception.ts @@ -12,6 +12,6 @@ export class CurrentPasswordRequiredException extends RuntimeException { ...options, }); - this.errorCode = 'CURRENT_PASSWORD_REQUIRED_ERROR'; + this.errorCode = 'PASSWORD_CURRENT_REQUIRED_ERROR'; } }