fix(error-handling): Removed appRef.tick() to avoid unnecessary errors. (TV-944)
Merge in TEA/mina-sidor-fa-web from feature/TV-944 to develop Squashed commit of the following: commit f51b753d96030235edb641daac8ecf6b428d1557 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Wed Dec 8 09:13:58 2021 +0100 Removed appRef.tick()
This commit is contained in:
@@ -5,7 +5,6 @@ import localeSe from '@angular/common/locales/sv';
|
||||
import { ErrorHandler, LOCALE_ID, NgModule, Provider } from '@angular/core';
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { ApmErrorHandler } from '@elastic/apm-rum-angular';
|
||||
import { environment } from '@msfa-environment';
|
||||
import { AuthInterceptor } from '@msfa-interceptors/auth.interceptor';
|
||||
import { CustomErrorHandler } from '@msfa-interceptors/custom-error-handler';
|
||||
import { AppRoutingModule } from './app-routing.module';
|
||||
@@ -22,14 +21,6 @@ const providers: Provider[] = [
|
||||
{ provide: ErrorHandler, useClass: CustomErrorHandler },
|
||||
];
|
||||
|
||||
// Skip error handler in Dev until "Uncaught Error: ApplicationRef.tick is called recursively" is fixed
|
||||
if (environment.production) {
|
||||
providers.push({
|
||||
provide: ErrorHandler,
|
||||
useClass: CustomErrorHandler,
|
||||
});
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
declarations: [AppComponent],
|
||||
imports: [
|
||||
|
||||
@@ -19,11 +19,11 @@ export class ToastComponent implements AfterViewInit {
|
||||
ErrorSeverity = ErrorSeverity;
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
// if (this.error.removeAfter) {
|
||||
// setTimeout(() => {
|
||||
// this.closeToast.emit(this.error);
|
||||
// }, this.error.removeAfter);
|
||||
// }
|
||||
if (this.error.removeAfter) {
|
||||
setTimeout(() => {
|
||||
this.closeToast.emit(this.error);
|
||||
}, this.error.removeAfter);
|
||||
}
|
||||
}
|
||||
|
||||
get className(): string {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ApplicationRef, Injectable, Injector } from '@angular/core';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { CustomError } from '@msfa-models/error/custom-error';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
@@ -7,29 +7,18 @@ import { map } from 'rxjs/operators';
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ErrorService {
|
||||
private appRef: ApplicationRef;
|
||||
private errorQueue$ = new BehaviorSubject<CustomError[]>([]);
|
||||
private _errorQueue$ = new BehaviorSubject<CustomError[]>([]);
|
||||
|
||||
public errors$: Observable<CustomError[]> = this.errorQueue$.pipe(
|
||||
public errors$: Observable<CustomError[]> = this._errorQueue$.pipe(
|
||||
map(errors => errors.sort((a, b) => (a.timestamp > b.timestamp ? -1 : 1)))
|
||||
);
|
||||
|
||||
constructor(private injector: Injector) {
|
||||
// Workaround to fix change-detection when using Error interceptor
|
||||
// See https://stackoverflow.com/a/37793791
|
||||
setTimeout(() => {
|
||||
this.appRef = this.injector.get(ApplicationRef);
|
||||
});
|
||||
}
|
||||
|
||||
public add(error: CustomError): void {
|
||||
this.errorQueue$.next([...this.errorQueue$.value, error]);
|
||||
this.appRef.tick();
|
||||
this._errorQueue$.next([...this._errorQueue$.value, error]);
|
||||
}
|
||||
|
||||
public remove(error: CustomError): void {
|
||||
const newErrorQueue = this.errorQueue$.value.filter(currentError => currentError.id !== error.id);
|
||||
this.errorQueue$.next(newErrorQueue);
|
||||
this.appRef.tick();
|
||||
const newErrorQueue = this._errorQueue$.value.filter(currentError => currentError.id !== error.id);
|
||||
this._errorQueue$.next(newErrorQueue);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user