2017-09-22 2 views
1

Angular HttpClient로 http 요청을하고 있습니다. 내 콘솔에서각도 4로 전체 오류 응답을 얻으려면 어떻게해야합니까?

http.get(`${hostUrl}/myproject/infrastructure-status`) 
.subscribe(
(resp) => { 
    // handle response 
}, 
(error) => { 
console.log(error) 
}); 

는 입력 HttpErrorResponse의 오류가 기록됩니다 Error logged on console

하지만, 내 네트워크 탭에있는 백엔드 응답은 동일하지 않습니다 :

Headers error network tab

enter image description here

전체 오류 응답을 각도로 가져올 수 있습니까? 그렇다면 어떻게?

답변

1

오류는 응답 객체이기도하므로 응답에 캐스팅하면 본문을 읽을 수 있습니다. 나이를 위해 작동 :

http.get(`${hostUrl}/myproject/infrastructure-status`) 
      .subscribe(
      (resp) => { 
       // handle response 
      }, 
      (error) => { 
       if (error instanceof Response) { 
       console.log(error.text()); 
       } 
      }); 

무엇을 나에게 이상한 것 같다 것은 당신이 ProgressEventObject를 얻을 수 있다는 것입니다. 나는 항상 몸도 포함하는 Response 객체를 얻는다. 아마도 차이점은 JSON을 반환하는 WebApi를 호출하여 테스트 한 HTML이라는 것입니다.

+0

ProgressEvent는 플래그로 얻을 수 있습니다. – Zlatko

관련 문제