Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // NavBar Template
- <div class="errors" *ngIf="errorInterceptor.errors.value | async">
- <div class="error"><b>prova {{errorInterceptor.errors.value}}</b></div>
- </div>
- //ErrorInterceptor
- @Injectable()
- export class ErrorInterceptor implements HttpInterceptor {
- constructor(private authenticationService: AuthenticationService, private router: Router) {}
- errors = new BehaviorSubject<string>(null);
- intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
- //next.handle(request) trasforma un HttpRequest in uno stream di HttpEvents,
- //restituisce un Observable <HttpEvent> 'Union type for all possible events on the response stream.'
- return next.handle(request).pipe(catchError(err => {
- if (err.status >= 400 && err.status < 500) {
- // auto logout if 401 response returned from api
- //this.authenticationService.logout();
- //location.reload(true);
- //console.error("Error:="+err.error.msg);
- //this.router.navigate(['/login']);
- console.error('error-interceptor:error status=' + err.status);
- this.errors.next(err.error);
- } else {
- console.error('error-interceptor:err=' + err.error + ' statusText=' + err.statusText + ' status:' + err.status);
- this.errors.next(err.error);
- }
- const error = err.error.msg || err.statusText;
- return throwError(error);
- }))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement