When HttpStatusCodeException exception raised?

Nag-Raj picture Nag-Raj · Dec 20, 2017 · Viewed 15.2k times · Source

when i use below code , what is the case to get HttpStatusCodeException exception .

ResponseEntity<Object> response = 
  restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, entity, Object.class);

Please can anyone help out ????????

Answer

gtosto picture gtosto · Dec 20, 2017

According to documentation there are two types of HttpStatusCodeException HttpClientErrorException and HttpServerErrorException.

  • The former is thrown when an HTTP 4xx is received.
  • The latter is thrown when an HTTP 5xx is received.

so you can just use ResponseEntity.BodyBuilder.status(505) for example to raise an HttpServerErrorException in your