Angular Interceptor With Subscribe Not WorkingProperly

Hi I have created an interceptor to refresh the token if token expires. Everything is fine except that when token expires before all the interceptor subscribe method gets executed the calling function throws an error.

this._customerService.getCustomers(this._customerSearchComp).subscribe(
  (data:any) => {
    
    }
  },
  (error) => {
    this.loader = false;  
    console.log("Inside error while retrieving customer");    
    this.notifyService.openSnackBar('error Thrown' + error, 'snackbar-warning');//this error is thrown before the interceptor subscribe method works
  }

And Here is my interceptor.

return next.handle(request).do((event: HttpEvent<any>) => {
  if (event instanceof HttpResponse) {
  }
}, async (err: any) => {
  if (err instanceof HttpErrorResponse) {
   if (err.status === 401) {
      debugger;
      let token = this._tokenService.getAuthToken();
      let refreshToken=this._tokenService.getRefreshToken(); 


      return this._authenticationService
        .refreshToken({
          token: token,
          refreshToken: refreshToken,
        })
        .subscribe(
          (data: any) => {
            debugger;
            console.log("Token Refreshed");
            this._tokenService.setToken(data.token);
            this._tokenService.setRefreshToken(data.refreshToken);
            return next.handle(request);
          },
          (error) => {
            this.dialogRef.closeAll();
            this.notifyService.isTokenExpired=true;
            this._router.navigate(['/']);
          }
        );
      
      }
    }
  });

Source: Angular Questions