RestTemplte.getForEntity 등 각종 함수에서 RestClientException (RUNTIME Exception)을 throw한다.


하지만 이 에러는 code를 표시하지 않기 때문에,


HttpClientErrorException을 catch하는게 좋다.




Class HttpClientErrorException

이렇게 HttpClientErrorException은 RestClientException을 상속받으며, 우리가 http를 주로사용하기 때문에

대부분이 여기에 해당된다.


사용법은 REF 첫번째 answer과 같이... 사용하면 된다.


try {
        ResponseEntity<StoreDto> r = restTemplate.getForEntity(url, StoreDto.class, m);
    }
    catch (final HttpClientErrorException e) {
        System.out.println(e.getStatusCode());
        System.out.println(e.getResponseBodyAsString());
    }


404에러 등이 잡힌다. 


Posted by yongary
,