|
1 | | -import { Injectable } from '@angular/core'; |
| 1 | +import { Injectable, Injector, NgZone } from '@angular/core'; |
2 | 2 | import { Router } from '@angular/router'; |
3 | 3 | import { SentryErrorHandler } from '@sentry/angular'; |
4 | 4 | import { environment } from 'src/environments/environment'; |
5 | 5 | import { TaskManagerService } from './services/task-manager.service'; |
6 | 6 | import { UserStateService } from './services/user-state-service'; |
7 | | -import { IErrorNavigationState } from './pages/participant/error-page/error-page.component'; |
| 7 | +import { IErrorNavigationState } from './pages/error-page/error-page.component'; |
8 | 8 |
|
9 | 9 | @Injectable() |
10 | 10 | export default class CustomErrorHandler extends SentryErrorHandler { |
11 | 11 | constructor( |
12 | 12 | private _router: Router, |
13 | 13 | private taskManager: TaskManagerService, |
14 | | - private userStateService: UserStateService |
| 14 | + private userStateService: UserStateService, |
| 15 | + private injector: Injector |
15 | 16 | ) { |
16 | 17 | super(); |
17 | 18 | } |
18 | 19 |
|
19 | 20 | handleError(error: string | Error): void { |
20 | | - this._router.navigate(['/task-error'], { |
21 | | - state: { |
22 | | - taskIndex: this.taskManager?.currentStudyTask?.taskOrder, |
23 | | - studyId: this.taskManager?.currentStudyTask?.studyId, |
24 | | - stackTrace: error instanceof Error ? error.stack : error, |
25 | | - userId: this.userStateService.currentlyLoggedInUserId, |
26 | | - } as IErrorNavigationState, |
| 21 | + const ngZone = this.injector.get(NgZone); |
| 22 | + ngZone.run(() => { |
| 23 | + this._router.navigate(['task-error'], { |
| 24 | + state: { |
| 25 | + taskIndex: this.taskManager?.currentStudyTask?.taskOrder, |
| 26 | + studyId: this.taskManager?.currentStudyTask?.studyId, |
| 27 | + stackTrace: error instanceof Error ? error.stack : error, |
| 28 | + userId: this.userStateService.currentlyLoggedInUserId, |
| 29 | + } as IErrorNavigationState, |
| 30 | + }); |
27 | 31 | }); |
| 32 | + |
28 | 33 | if (environment.production) { |
29 | 34 | super.handleError(error); |
30 | 35 | } |
|
0 commit comments