Skip to content

Commit

Permalink
Log Request body, when exception is encountered invoking Goonj SF req…
Browse files Browse the repository at this point in the history
…uest
  • Loading branch information
himeshr committed Sep 19, 2022
1 parent 88d480c commit 4b99783
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -77,12 +78,17 @@ protected <T> T getSingleEntityResponse(String resource, String filter, String u
protected HashMap<String, Object>[] createSingleEntity(String resource, HttpEntity<?> requestEntity) throws RestClientResponseException {
URI uri = URI.create(String.format("%s/%s", goonjConfig.getAppUrl(), resource));
ParameterizedTypeReference<HashMap<String, Object>[]> responseType = new ParameterizedTypeReference<>() {};
ResponseEntity<HashMap<String, Object>[]> responseEntity = goonjRestTemplate.exchange(uri, HttpMethod.POST, requestEntity, responseType);
if(responseEntity.getStatusCode().is2xxSuccessful()) {
return responseEntity.getBody();
try {
ResponseEntity<HashMap<String, Object>[]> 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<HashMap<String, Object>[]> responseEntity, HttpStatus statusCode) {
Expand Down

0 comments on commit 4b99783

Please sign in to comment.