2017-11-16 3 views
0

코드에서 나는 http 요청을 가로 채려고합니다. http 연결을 설정할 수있을 때마다 인터셉터가 작동하지만, net::ERR_CONNECTION_REFUSED을 얻은 경우 event 변수는 HttpResponse의 인스턴스가 아니므로 이러한 종류의 오류는 처리 할 수 ​​없습니다. 여기 내 코드는 다음과 같습니다각도 4 - 인터셉터 핸들 net :: ERR_CONNECTION_REFUSED

내가 net::ERR_CONNECTION_REFUSED 같은 인터셉터 오류를 감지 할 수있는 방법
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { 
    this.changeStatus(false); 
    this.requests_count++; 
    const my_req = req.clone({ 
     url: API_PATH + req.url 
    }); 
    return next 
     .handle(my_req) 
     .do(event => { 
      if (event instanceof HttpResponse) { 
       this.requests_count--; 
       if (!this.requests_count) 
        this.changeStatus(true); 
      } 
     }); 
} 

?

답변

0

방금 ​​가져 왔습니다.

.do(
    event => { 
     if (event instanceof HttpResponse) { 
      this.requests_count--; 
      if (!this.requests_count) 
       this.changeStatus(true); 
     } 
    }, 
    error => { 
     if (error instanceof HttpErrorResponse) { 
      this.requests_count--; 
      if (!this.requests_count) 
       this.changeStatus(true); 
     } 
    } 
); 
관련 문제