fix(progress-bar): stop loading in case of error (#142)
Stop progress bar loading indicator in case of an HTTP Error Response. Fixes #141
This commit is contained in:
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
|
||||
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse} from '@angular/common/http';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { tap } from 'rxjs/operators';
|
||||
import { tap, catchError } from 'rxjs/operators';
|
||||
|
||||
import { ProgressBarService } from './progress-bar.service';
|
||||
|
||||
@@ -13,13 +13,19 @@ export class ProgressInterceptor implements HttpInterceptor {
|
||||
|
||||
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||
this.progressBarService.increase();
|
||||
return next
|
||||
.handle(request).pipe(
|
||||
return next.handle(request)
|
||||
.pipe(
|
||||
tap(event => {
|
||||
if (event instanceof HttpResponse) {
|
||||
this.progressBarService.decrease();
|
||||
}
|
||||
})
|
||||
)
|
||||
.pipe(
|
||||
catchError(error => {
|
||||
this.progressBarService.decrease();
|
||||
throw error;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user