conceptadev / rockets

Rapid Enterprise Development Toolkit
https://www.rockets.tools
BSD 3-Clause "New" or "Revised" License
87 stars 12 forks source link

Bug: Original Error Not Sent to Sentry in AwsStorageException #292

Open tnramalho opened 1 day ago

tnramalho commented 1 day ago

When throwing the following exception:

throw new AwsStorageException({
  safeMessage: 'Error downloading file from S3',
  originalError: error,
});

Only the text 'Error downloading file from S3' appears in Sentry. It seems that the originalError is not being sent to Sentry for better traceability.

Expected Behavior Both the safeMessage and the originalError should be captured and logged in Sentry, ensuring that the original error information is available for debugging.

Actual Behavior Currently, only the safeMessage ('Error downloading file from S3') is showing up in Sentry, with no trace of the originalError information.

Steps to Reproduce

Add global exception filter

import { ExceptionsFilter } from '@concepta/nestjs-exception';

// ... 
const exceptionsFilter = app.get(HttpAdapterHost);
 app.useGlobalFilters(new ExceptionsFilter(exceptionsFilter));

Register LoggeModule and LoggerSentryModule make sure to use proper Sentry configurations

// ... 
 LoggerSentryModule.forRoot({}),
    LoggerModule.forRootAsync({
      inject: [LoggerSentryTransport],
      useFactory: (
        loggerSentryTransport: LoggerSentryTransport,
      ) => {
        return {
          transports: [loggerSentryTransport],
        };
      },
    }),

Create the custom AwsStorageException class:

import {
  RuntimeException,
  RuntimeExceptionContext,
  RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class AwsStorageException extends RuntimeException {
  context: RuntimeExceptionContext;

  constructor(options: RuntimeExceptionOptions) {
    super(options);
    this.errorCode = 'AWS_STORAGE_ERROR';
  }
}

Trigger the exception with the following code snippet:

throw new AwsStorageException({
  safeMessage: 'Error downloading file from S3',
  originalError: error,
});

Check the Sentry logs for the captured exception.

Observe that only the safeMessage is logged, with no trace of the originalError.

Additional Information Version: 5.0.0-alpha.4

MrMaz commented 1 day ago

Please add this feature to the logger and sentry logger modules and validate agains the scenario reported.