Skip to content

Commit

Permalink
chore: update mr changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tnramalho committed Oct 17, 2024
1 parent 0b4bec9 commit d333d80
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export class InvalidCredentialsException extends RuntimeException {
...options,
});

this.errorCode = 'INVALID_CREDENTIALS_ERROR';
this.errorCode = 'AUTH_LOCAL_INVALID_CREDENTIALS_ERROR';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export class InvalidLoginDataException extends RuntimeException {
...options,
});

this.errorCode = 'INVALID_LOGIN_DATA_ERROR';
this.errorCode = 'AUTH_LOCAL_INVALID_LOGIN_DATA_ERROR';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { RuntimeExceptionInterface } from '@concepta/nestjs-exception';

export interface LoggerSentryExtrasInterface
extends Partial<
Pick<RuntimeExceptionInterface, 'errorCode' | 'safeMessage' | 'context'>
> {
statusCode?: number;
message?: string | unknown;
originalError?: Error | string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ describe('loggerSentryTransport', () => {
statusCode: exception?.httpStatus,
message: exception?.message,
safeMessage: exception?.safeMessage,
originalError: exception?.context?.originalError,
context: exception?.context,

Check failure on line 192 in packages/nestjs-logger-sentry/src/transports/logger-sentry.transport.spec.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Delete `⏎`
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
}
11 changes: 9 additions & 2 deletions packages/nestjs-org/src/exceptions/org-member.exception.ts
Original file line number Diff line number Diff line change
@@ -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<RuntimeExceptionOptions, 'message'>,
) {
super({
message,
...options,
});
this.errorCode = 'ORG_MEMBER_ERROR';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export class CurrentPasswordRequiredException extends RuntimeException {
...options,
});

this.errorCode = 'CURRENT_PASSWORD_REQUIRED_ERROR';
this.errorCode = 'PASSWORD_CURRENT_REQUIRED_ERROR';
}
}

0 comments on commit d333d80

Please sign in to comment.