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.handleSentryError(error, request);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
this.handleSentryError(error, request);
if (error.status >= 500) {
this.sendErrorToSentry(error, request);
}

Copy link
Contributor Author

@devendrafyle devendrafyle Jan 15, 2025

Choose a reason for hiding this comment

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

this condition is considered by sendErrorToSentry method itself.
image

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

private handleSentryError(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
24 changes: 20 additions & 4 deletions src/app/fyle/my-view-report/my-view-report.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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';
import { HttpErrorResponse } from '@angular/common/http';

Check failure on line 41 in src/app/fyle/my-view-report/my-view-report.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

'HttpErrorResponse' is defined but never used

@Component({
selector: 'app-my-view-report',
Expand Down Expand Up @@ -466,12 +467,27 @@
this.trackingService.showToastMessage({ ToastContent: message });
},
error: (error) => {
// Capture error with additional details in Sentry
Sentry.captureException(error, {
const errorMessage = `Report Submit Error ${error.status}: ${error.error?.message || error.statusText || 'Unknown Error'}`;

Check failure on line 470 in src/app/fyle/my-view-report/my-view-report.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

Unsafe member access .status on an `any` value

Check failure on line 470 in src/app/fyle/my-view-report/my-view-report.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

Unsafe member access .error on an `any` value

Check failure on line 470 in src/app/fyle/my-view-report/my-view-report.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

Unsafe member access .statusText on an `any` value
const errorObj = new Error(errorMessage);

Check failure on line 472 in src/app/fyle/my-view-report/my-view-report.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

Trailing spaces not allowed
Object.assign(errorObj, {
status: error.status,

Check failure on line 474 in src/app/fyle/my-view-report/my-view-report.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

Unsafe assignment of an `any` value

Check failure on line 474 in src/app/fyle/my-view-report/my-view-report.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

Unsafe member access .status on an `any` value
url: error.url,

Check failure on line 475 in src/app/fyle/my-view-report/my-view-report.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

Unsafe assignment of an `any` value

Check failure on line 475 in src/app/fyle/my-view-report/my-view-report.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

Unsafe member access .url on an `any` value
responseData: error.error,

Check failure on line 476 in src/app/fyle/my-view-report/my-view-report.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

Unsafe assignment of an `any` value
name: `ReportSubmitError_${this.reportId}`
});

Sentry.captureException(errorObj, {
tags: {
errorType: 'REPORT_SUBMIT_ERROR',
reportId: this.reportId
},
extra: {
reportId: this.reportId,
errorResponse: error,
},
responseStatus: error.status,
responseData: error.error,
page: 'submit_report'
}
});
},
});
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
Loading