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:
Abhay Chawla
2018-07-21 21:57:10 +05:30
committed by GitHub
parent ec7e871ac6
commit ccb2f009db
+9 -3
View File
@@ -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;
})
);
}