Skip to content

Commit 1c13161

Browse files
committed
MOTECH-3178: Fixed PMD issue.
1 parent 0c10641 commit 1c13161

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

openmrs/src/main/java/org/motechproject/openmrs/exception/OpenMRSException.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package org.motechproject.openmrs.exception;
22

3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.web.client.HttpClientErrorException;
6+
37
/**
48
* Thrown when there were problems while fetching data from OpenMRS server.
59
*/
610
public class OpenMRSException extends RuntimeException {
11+
private static final Logger LOGGER = LoggerFactory.getLogger(OpenMRSException.class);
712

813
public OpenMRSException(Throwable e) {
914
super(e);
@@ -15,5 +20,10 @@ public OpenMRSException(String message) {
1520

1621
public OpenMRSException(String message, Throwable cause) {
1722
super(message, cause);
23+
24+
if (cause instanceof HttpClientErrorException) {
25+
HttpClientErrorException httpCause = (HttpClientErrorException) cause;
26+
LOGGER.debug("{} {} {}", message, httpCause.getMessage(), httpCause.getResponseBodyAsString());
27+
}
1828
}
1929
}

openmrs/src/main/java/org/motechproject/openmrs/resource/impl/BaseResource.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.springframework.http.HttpMethod;
1111
import org.springframework.http.MediaType;
1212
import org.springframework.http.ResponseEntity;
13-
import org.springframework.web.client.HttpClientErrorException;
1413
import org.springframework.web.client.RestOperations;
1514

1615
import java.net.URI;
@@ -62,14 +61,9 @@ protected String postForJson(Config config, String json, String path, Object...
6261
LOGGER.debug("{} request body: {}", buildUrl(config, path, params), json);
6362
String responseJson;
6463

65-
try {
66-
ResponseEntity<String> responseEntity = exchange(config, buildUrl(config, path, params), HttpMethod.POST, json, headers);
67-
responseJson = responseEntity.getBody();
68-
LOGGER.debug("{} response body with HTTP CODE {}: {}", buildUrl(config, path, params), responseEntity.getStatusCode(), responseJson);
69-
} catch(HttpClientErrorException e) {
70-
LOGGER.debug("{} {} {}", buildUrl(config, path, params), e.getMessage(), e.getResponseBodyAsString());
71-
throw new HttpClientErrorException(e.getStatusCode(), e.getStatusText(), e.getResponseBodyAsByteArray(), null);
72-
}
64+
ResponseEntity<String> responseEntity = exchange(config, buildUrl(config, path, params), HttpMethod.POST, json, headers);
65+
responseJson = responseEntity.getBody();
66+
LOGGER.debug("{} response body with HTTP CODE {}: {}", buildUrl(config, path, params), responseEntity.getStatusCode(), responseJson);
7367

7468
return responseJson;
7569
}

0 commit comments

Comments
 (0)