Skip to content
25 changes: 25 additions & 0 deletions src/app/core/interceptors/httpInterceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { SecureStorageService } from '../services/secure-storage.service';
import { StorageService } from '../services/storage.service';
import { TokenService } from '../services/token.service';
import { UserEventService } from '../services/user-event.service';
import * as Sentry from '@sentry/angular';

@Injectable()
export class HttpConfigInterceptor implements HttpInterceptor {
Expand Down Expand Up @@ -153,6 +154,7 @@ export class HttpConfigInterceptor implements HttpInterceptor {
return next.handle(request).pipe(
catchError((error) => {
if (error instanceof HttpErrorResponse) {
this.trackErrorInSentry(error, request);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Aiyyo, please sanitize sensitive data before calling trackErrorInSentry.
My friend, always ensure we don't pass confidential user details or tokens directly to Sentry. Consider sanitizing relevant headers, body, or error responses here.

if (this.expiringSoon(token)) {
return from(this.refreshAccessToken()).pipe(
mergeMap((newToken) => {
Expand All @@ -177,6 +179,29 @@ export class HttpConfigInterceptor implements HttpInterceptor {
})
);
}

private trackErrorInSentry(error: HttpErrorResponse, request: HttpRequest<string>): void {
if (error.status >= 500) {
const errorObject = new Error(`API ${error.status} Error: ${error.message || 'Server error'}`);

Object.assign(errorObject, {
status: error.status,
statusText: error.statusText,
name: `API Error ${error.status} : ${error.url?.split('?')[0]}`,
});

Sentry.captureException(errorObject, {
tags: {
errorType: `API_${error.status}`,
apiEndpoint: error.url,
},
extra: {
requestUrl: request.url,
responseData: error.error,
},
});
}
}
}

export class CustomEncoder implements HttpParameterCodec {
Expand Down
28 changes: 8 additions & 20 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,7 +37,6 @@ 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';

@Component({
selector: 'app-my-view-report',
Expand Down Expand Up @@ -455,25 +454,14 @@ export class MyViewReportPage {
this.spenderReportsService
.submit(this.reportId)
.pipe(finalize(() => (this.submitReportLoader = false)))
.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,
},
});
},
.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 });
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,23 @@ export class CameraPreviewComponent implements OnInit, OnChanges {
stopCamera(): void {
//Stop camera only if it is in RUNNING state
if (this.cameraState === CameraState.RUNNING) {
const currentCameraState = this.cameraState;
this.cameraState = CameraState.STOPPING;
from(this.cameraPreviewService.stop()).subscribe(() => (this.cameraState = CameraState.STOPPED));

from(this.cameraPreviewService.stop()).subscribe({
next: () => {
this.cameraState = CameraState.STOPPED;
},
error: (error) => {
Sentry.captureException(error, {
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above

extra: {
errorResponse: error,
currentCameraState,
cameraState: this.cameraState,
},
});
},
});
}
}

Expand Down