Skip to content

Commit 2f73d39

Browse files
author
nehashri
committed
Neha | SHR-1367 | storing error message in failed events table.
1 parent 2038ead commit 2f73d39

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

  • shrclient-omod/src/main/java/org/openmrs/module/shrclient/util

shrclient-omod/src/main/java/org/openmrs/module/shrclient/util/WebClient.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,19 @@ private String execute(final HttpRequestBase request, boolean allowRedirection)
9898
ResponseHandler<String> responseHandler = new ResponseHandler<String>() {
9999
public String handleResponse(final HttpResponse response) throws IOException {
100100
int status = response.getStatusLine().getStatusCode();
101+
HttpEntity entity = response.getEntity();
102+
String content = parseContentInputAsString(entity);
101103
if (status >= 200 && status < 300) {
102-
HttpEntity entity = response.getEntity();
103-
return entity != null ? parseContentInputAsString(entity) : null;
104+
return entity != null ? content : null;
104105
} else if (status == HttpStatus.NOT_FOUND.value()) {
105106
return null;
106107
} else if (status == HttpStatus.UNAUTHORIZED.value()) {
107108
throw new IdentityUnauthorizedException("Identity not authorized");
109+
} else if (status == HttpStatus.FORBIDDEN.value()) {
110+
throw new ClientProtocolException("Access is denied: " + status);
111+
} else if (status >= 400 && status < 500) {
112+
String errorMessage = String.format("Unexpected response status: %s. Response returned is %s.\n", status, content);
113+
throw new ClientProtocolException(errorMessage);
108114
} else {
109115
throw new ClientProtocolException("Unexpected response status: " + status);
110116
}
@@ -145,5 +151,4 @@ private Map<String, String> getCommonHeaders() {
145151
private String getUrl(String path) {
146152
return StringUtil.ensureSuffix(baseUrl, "/") + StringUtil.removePrefix(path, "/");
147153
}
148-
149154
}

0 commit comments

Comments
 (0)