-
Notifications
You must be signed in to change notification settings - Fork 15
chore: Added sentry call for 500 API errors #3413
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
b9a0e33
6a43ef7
3029a6c
d658403
d0571db
b9f09f1
7442ce4
a6ba32a
fa8dbee
7e11fba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
|
@@ -153,6 +154,7 @@ export class HttpConfigInterceptor implements HttpInterceptor { | |
| return next.handle(request).pipe( | ||
| catchError((error) => { | ||
| if (error instanceof HttpErrorResponse) { | ||
| this.handleSentryError(error, request); | ||
| if (this.expiringSoon(token)) { | ||
| return from(this.refreshAccessToken()).pipe( | ||
| mergeMap((newToken) => { | ||
|
|
@@ -177,6 +179,44 @@ 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, | ||
| }); | ||
|
|
||
| Sentry.captureException(errorObject, { | ||
| tags: { | ||
| errorType: 'API_500', | ||
| apiEndpoint: error.url, | ||
| }, | ||
| extra: { | ||
| requestUrl: request.url, | ||
| requestMethod: request.method, | ||
| requestHeaders: request.headers, | ||
| requestBody: request.body, | ||
| responseStatus: error.status, | ||
| responseStatusText: error.statusText, | ||
| responseData: error.error, | ||
| }, | ||
| }); | ||
|
||
|
|
||
| Sentry.addBreadcrumb({ | ||
| category: 'api', | ||
| message: `API call failed with status ${error.status}`, | ||
| level: 'error', | ||
| data: { | ||
| url: request.url, | ||
| method: request.method, | ||
| status: error.status, | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export class CustomEncoder implements HttpParameterCodec { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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', | ||
|
|
@@ -455,12 +456,38 @@ export class MyViewReportPage { | |
| }); | ||
| this.trackingService.showToastMessage({ ToastContent: message }); | ||
| }, | ||
| error: (error) => { | ||
| // Capture error with additional details in Sentry | ||
| Sentry.captureException(error, { | ||
| error: (error: HttpErrorResponse) => { | ||
| const errorObject = new Error(`Report Submission Failed: ${error.message || 'Unknown error'}`); | ||
|
||
| if (error.status) { | ||
| Object.assign(errorObject, { | ||
| status: error.status, | ||
| statusText: error.statusText, | ||
| }); | ||
| } | ||
|
|
||
| Sentry.addBreadcrumb({ | ||
| category: 'reports', | ||
| message: 'Failed to submit report', | ||
| level: 'error', | ||
| data: { | ||
| reportId: this.reportId, | ||
| errorStatus: error.status, | ||
| errorMessage: error.message, | ||
| }, | ||
| }); | ||
|
|
||
| Sentry.captureException(errorObject, { | ||
| tags: { | ||
| errorType: 'REPORT_SUBMISSION_FAILED', | ||
| reportId: this.reportId, | ||
| }, | ||
| extra: { | ||
| reportId: this.reportId, | ||
| errorResponse: error, | ||
| context: { | ||
| component: 'ReportSubmissionComponent', | ||
| action: 'submitReport', | ||
| }, | ||
|
||
| }, | ||
| }); | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
| extra: { | ||
| errorResponse: error, | ||
| currentCameraState, | ||
| cameraState: this.cameraState, | ||
| }, | ||
| }); | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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

sendErrorToSentrymethod itself.