From 4b997835c46751dd061510fb74db1442ef5aa8db Mon Sep 17 00:00:00 2001 From: himeshr Date: Mon, 19 Sep 2022 18:31:47 +0530 Subject: [PATCH] Log Request body, when exception is encountered invoking Goonj SF request --- .../goonj/repository/GoonjBaseRepository.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/goonj/src/main/java/org/avni_integration_service/goonj/repository/GoonjBaseRepository.java b/goonj/src/main/java/org/avni_integration_service/goonj/repository/GoonjBaseRepository.java index 351749cc..7fbbfa0e 100644 --- a/goonj/src/main/java/org/avni_integration_service/goonj/repository/GoonjBaseRepository.java +++ b/goonj/src/main/java/org/avni_integration_service/goonj/repository/GoonjBaseRepository.java @@ -7,6 +7,7 @@ import org.avni_integration_service.goonj.config.GoonjConfig; import org.avni_integration_service.goonj.util.DateTimeUtil; import org.avni_integration_service.integration_data.repository.IntegratingEntityStatusRepository; +import org.avni_integration_service.util.ObjectJsonMapper; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.*; import org.springframework.web.client.*; @@ -77,12 +78,17 @@ protected T getSingleEntityResponse(String resource, String filter, String u protected HashMap[] createSingleEntity(String resource, HttpEntity requestEntity) throws RestClientResponseException { URI uri = URI.create(String.format("%s/%s", goonjConfig.getAppUrl(), resource)); ParameterizedTypeReference[]> responseType = new ParameterizedTypeReference<>() {}; - ResponseEntity[]> responseEntity = goonjRestTemplate.exchange(uri, HttpMethod.POST, requestEntity, responseType); - if(responseEntity.getStatusCode().is2xxSuccessful()) { - return responseEntity.getBody(); + try { + ResponseEntity[]> responseEntity = goonjRestTemplate.exchange(uri, HttpMethod.POST, requestEntity, responseType); + if (responseEntity.getStatusCode().is2xxSuccessful()) { + return responseEntity.getBody(); + } + logger.error(String.format("Failed to create resource %s, response status code is %s", resource, responseEntity.getStatusCode())); + throw handleError(responseEntity, responseEntity.getStatusCode()); + } catch(Exception e) { + logger.error("Error request body:" + ObjectJsonMapper.writeValueAsString(requestEntity.getBody()), e); + throw e; } - logger.error(String.format("Failed to create resource %s, response status code is %s", resource, responseEntity.getStatusCode())); - throw handleError(responseEntity, responseEntity.getStatusCode()); } protected RestClientException handleError(ResponseEntity[]> responseEntity, HttpStatus statusCode) {