Spring MVC – RestTemplate launch exception when http 404 happens

As far as I’m aware, you can’t get an actual ResponseEntity, but the status code and body (if any) can be obtained from the exception:

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)