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 sentry call for 500 API errors #3413

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
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
26 changes: 22 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 { ExtendedComment } from 'src/app/core/models/platform/v1/extended-commen
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';

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

Object.assign(errorObj, {
status: error.status,
url: error.url,
responseData: error.message,
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