Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Added the sentry to trace issues #3368

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/app/fyle/my-view-report/my-view-report.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { ReportPermissions } from 'src/app/core/models/report-permissions.model'
import { ExtendedComment } from 'src/app/core/models/platform/v1/extended-comment.model';
import { Comment } from 'src/app/core/models/platform/v1/comment.model';
import { ExpenseTransactionStatus } from 'src/app/core/enums/platform/v1/expense-transaction-status.enum';
import * as Sentry from '@sentry/angular';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Kabali style! Let's make error handling consistent across the app!

While the import is correct, I notice we're implementing Sentry tracking in multiple components individually.

Consider creating a centralized error handling service:

// src/app/core/services/error-tracking.service.ts
import * as Sentry from '@sentry/angular';

@Injectable({
  providedIn: 'root'
})
export class ErrorTrackingService {
  captureError(error: Error, context: Record<string, unknown>) {
    Sentry.captureException(error, {
      extra: {
        errorType: error.name,
        errorMessage: error.message,
        timestamp: new Date().toISOString(),
        ...context
      }
    });
  }
}


@Component({
selector: 'app-my-view-report',
Expand Down Expand Up @@ -444,14 +445,25 @@ export class MyViewReportPage {
}

submitReport(): void {
this.spenderReportsService.submit(this.reportId).subscribe(() => {
this.router.navigate(['/', 'enterprise', 'my_reports']);
const message = `Report submitted successfully.`;
this.matSnackBar.openFromComponent(ToastMessageComponent, {
...this.snackbarProperties.setSnackbarProperties('success', { message }),
panelClass: ['msb-success-with-camera-icon'],
});
this.trackingService.showToastMessage({ ToastContent: message });
this.spenderReportsService.submit(this.reportId).subscribe({
next: () => {
this.router.navigate(['/', 'enterprise', 'my_reports']);
const message = `Report submitted successfully.`;
this.matSnackBar.openFromComponent(ToastMessageComponent, {
...this.snackbarProperties.setSnackbarProperties('success', { message }),
panelClass: ['msb-success-with-camera-icon'],
});
this.trackingService.showToastMessage({ ToastContent: message });
},
error: (error) => {
// Capture error with additional details in Sentry
Sentry.captureException(error, {
extra: {
reportId: this.reportId,
errorResponse: error,
},
});
},
Comment on lines +448 to +466
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Mind it! The error handling needs more punch!

The Sentry integration is good, but we can make it more robust and user-friendly.

Consider these improvements:

 submitReport(): void {
   this.spenderReportsService.submit(this.reportId).subscribe({
     next: () => {
       this.router.navigate(['/', 'enterprise', 'my_reports']);
       const message = `Report submitted successfully.`;
       this.matSnackBar.openFromComponent(ToastMessageComponent, {
         ...this.snackbarProperties.setSnackbarProperties('success', { message }),
         panelClass: ['msb-success-with-camera-icon'],
       });
       this.trackingService.showToastMessage({ ToastContent: message });
     },
     error: (error) => {
+      const errorMessage = 'Failed to submit report. Please try again.';
+      this.matSnackBar.openFromComponent(ToastMessageComponent, {
+        ...this.snackbarProperties.setSnackbarProperties('error', { message: errorMessage }),
+        panelClass: ['msb-error'],
+      });
       Sentry.captureException(error, {
         extra: {
           reportId: this.reportId,
-          errorResponse: error,
+          errorType: error.name,
+          errorMessage: error.message,
+          userId: this.eou?.us?.id,
+          timestamp: new Date().toISOString()
         },
       });
+      // Retry submission after a delay if it's a network error
+      if (error.name === 'NetworkError') {
+        setTimeout(() => this.submitReport(), 5000);
+      }
     },
   });
 }

Committable suggestion skipped: line range outside the PR's diff.

});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DEVICE_PLATFORM } from 'src/app/constants';
import { CameraState } from 'src/app/core/enums/camera-state.enum';
import { CameraPreviewService } from 'src/app/core/services/camera-preview.service';
import { CameraService } from 'src/app/core/services/camera.service';
import * as Sentry from '@sentry/angular';

@Component({
selector: 'app-camera-preview',
Expand Down Expand Up @@ -81,6 +82,7 @@ export class CameraPreviewComponent implements OnInit, OnChanges {

startCameraPreview(): void {
if (![CameraState.STARTING, CameraState.RUNNING].includes(this.cameraState)) {
const currentCameraState = this.cameraState;
this.cameraState = CameraState.STARTING;
const cameraPreviewOptions: CameraPreviewOptions = {
position: 'rear',
Expand All @@ -91,9 +93,24 @@ export class CameraPreviewComponent implements OnInit, OnChanges {
disableAudio: true,
};

from(this.cameraPreviewService.start(cameraPreviewOptions)).subscribe(() => {
this.cameraState = CameraState.RUNNING;
this.getFlashModes();
from(this.cameraPreviewService.start(cameraPreviewOptions)).subscribe({
next: () => {
this.cameraState = CameraState.RUNNING;
this.getFlashModes();
},
error: (error) => {
Sentry.captureException(error, {
extra: {
errorResponse: error,
currentCameraState,
cameraState: this.cameraState,
navigationState: window.location.href,
options: cameraPreviewOptions,
platform: this.devicePlatform,
timestamp: new Date().toISOString(),
},
});
},
});
}
}
Expand Down
Loading