|
|
|
@@ -3,11 +3,14 @@ import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/c |
|
|
|
import { Observable, throwError } from 'rxjs'; |
|
|
|
import { catchError } from 'rxjs/operators'; |
|
|
|
|
|
|
|
import { AccountService } from '@app/_services'; |
|
|
|
import {AccountService, AlertService} from '@app/_services'; |
|
|
|
|
|
|
|
@Injectable() |
|
|
|
export class ErrorInterceptor implements HttpInterceptor { |
|
|
|
constructor(private accountService: AccountService) {} |
|
|
|
constructor( |
|
|
|
private accountService: AccountService, |
|
|
|
private alertService: AlertService |
|
|
|
) {} |
|
|
|
|
|
|
|
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { |
|
|
|
return next.handle(request).pipe(catchError(err => { |
|
|
|
@@ -16,6 +19,8 @@ export class ErrorInterceptor implements HttpInterceptor { |
|
|
|
this.accountService.logout(); |
|
|
|
} |
|
|
|
|
|
|
|
this.alertService.error(err.message); |
|
|
|
|
|
|
|
const error = err.error?.message || err.statusText; |
|
|
|
return throwError(() => error); |
|
|
|
})) |
|
|
|
|