0

I have a REST endpoint which call another API which take a while to process and returning 504 error when I verify through Rest client (Insomnia). But in my service I see this transaction as success 200 not 504.

Below is how my code snippet:

public ResponseEntity<Customer> processResponse(Customer customer, String restUri) {

    ResponseEntity<Customer> response;
    String customerJson = null;
    try {
        RestTemplate restTemplate = restTemplateBuilder.basicAuthorization(userName, password).build();
        HttpHeaders headers = new HttpHeaders();
        headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
        headers.setContentType(MediaType.APPLICATION_JSON);

        HttpEntity<Customer> entity = new HttpEntity<>(customer, headers);
        CustomerJson = jacksonUtil.toJSON(customer);
        response = restTemplate.exchange(restUri, HttpMethod.PUT, entity, Customer.class);

        if (response.getStatusCode().is2xxSuccessful()) {
            logger.info("Return success from the server");
        } else {
            logger.error("Error while getting the response from the server");
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        throw ex;
    }
    return response;
}

What am I missing here? Why its not executing the else block?

Thanks in advance.

user3919727
  • 283
  • 2
  • 7
  • 25

1 Answers1

0

Your method seems to be returning null response in case of error. Can you check if you have done any handling in caller and passing 200 from controller layer itself.

rahulP
  • 244
  • 2
  • 6