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 {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse} from '@angular/common/http';
|
||||||
|
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { tap } from 'rxjs/operators';
|
import { tap, catchError } from 'rxjs/operators';
|
||||||
|
|
||||||
import { ProgressBarService } from './progress-bar.service';
|
import { ProgressBarService } from './progress-bar.service';
|
||||||
|
|
||||||
@@ -13,13 +13,19 @@ export class ProgressInterceptor implements HttpInterceptor {
|
|||||||
|
|
||||||
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||||
this.progressBarService.increase();
|
this.progressBarService.increase();
|
||||||
return next
|
return next.handle(request)
|
||||||
.handle(request).pipe(
|
.pipe(
|
||||||
tap(event => {
|
tap(event => {
|
||||||
if (event instanceof HttpResponse) {
|
if (event instanceof HttpResponse) {
|
||||||
this.progressBarService.decrease();
|
this.progressBarService.decrease();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
)
|
||||||
|
.pipe(
|
||||||
|
catchError(error => {
|
||||||
|
this.progressBarService.decrease();
|
||||||
|
throw error;
|
||||||
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user