I need to unsubscribe
during a call but when I do this there is no HttpResponse
. This is a problem for me as I also am using an http
interceptor to catch when I should show a loading icon or not.
So in my specific component I have this:
if (this.testSubscription)
this.testSubscription.unsubscribe(); // Stop original http request when calling getTestDetails with other parameters
this.testSubscription = this.getTestDetails(param1, param2);
And my interceptor:
intercept(request: HttpRequest<any>, next: HttpHandler) {
this.totalRequests++;
console.log(' intercept totalRequests: ', this.totalRequests);
this.loadingService.isLoading.next(true);
return next.handle(request).pipe(
tap(res => {
if (res instanceof HttpResponse) {
// I need to get here even when unsubscribing !!!!
this.decreaseRequests();
}
}),
catchError(err => {
this.decreaseRequests();
throw err;
})
);
}
So I'm not really sure how I can trigger my intercept method to catch this when I unsubscribe
on the Subscription..
Any ideas are appreciated!