From b9792cbbd54b15fcb66cef47e2d55a1986a8c921 Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T Date: Thu, 18 Dec 2025 09:02:59 +0530 Subject: [PATCH] BAH-4348 | Fix. Consume response entity even if request is a failure --- .../main/java/org/bahmni/webclients/HttpClient.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/web-clients/src/main/java/org/bahmni/webclients/HttpClient.java b/web-clients/src/main/java/org/bahmni/webclients/HttpClient.java index bd6fb74..110aaf8 100644 --- a/web-clients/src/main/java/org/bahmni/webclients/HttpClient.java +++ b/web-clients/src/main/java/org/bahmni/webclients/HttpClient.java @@ -99,9 +99,16 @@ public R post(String url, T payload, Class returnType) throws IOExcept private void checkSanityOfResponse(HttpResponse httpResponse) { StatusLine statusLine = httpResponse.getStatusLine(); int statusCode = statusLine.getStatusCode(); - if (statusCode < 200 || statusCode >= 300) throw new WebClientsException("Bad response code of " + statusCode); - HttpEntity entity = httpResponse.getEntity(); + if (statusCode < 200 || statusCode >= 300) { + try { + EntityUtils.consume(entity); + } catch (IOException e) { + throw new WebClientsException("Unable to read response entity", e); + } + throw new WebClientsException("Bad response code of " + statusCode); + } + if (entity == null) throw new WebClientsException("Cannot read response"); }