0

I have a controller with this endpoint

@GetMapping("/users/userid")
public ResponseEntity getUser(@PathVariable Long cardId){
    Long userId = userService.getUserByCardId(cardId);

    if(userId == null){
        return new ResponseEntity(HttpStatus.NOT_FOUND);
    }

    return new ResponseEntity<>(userId, HttpStatus.OK);

}

I call this endpoint with a restemplate

ResponseEntity<Long> responseEntity = restTemplate.exchange(url HttpMethod.GET, null, Long.class);

System.out.println(responseEntity.getStatusCodeValue());

I never see the system out.

When I debug, I see 404 is returned

exchange call return

org.springframework.web.client.HttpClientErrorExcepton$NotFound: 404 [no body]
robert trudel
  • 5,283
  • 17
  • 72
  • 124
  • Does this answer your question? [Spring MVC - RestTemplate launch exception when http 404 happens](https://stackoverflow.com/questions/16194014/spring-mvc-resttemplate-launch-exception-when-http-404-happens) – Sotirios Delimanolis Mar 02 '21 at 05:57
  • See also https://stackoverflow.com/questions/32868970/spring-boot-how-to-ignore-httpstatus-exceptions – Sotirios Delimanolis Mar 02 '21 at 05:57

0 Answers0