Skip to content

Commit 60171e3

Browse files
jarpit96iluwatar
authored andcommitted
Fix for Issue iluwatar#549 : Update Exception Handling Code in Aggregator Microservice (iluwatar#958)
* Fix for Issue#iluwatar#549 Catch ClientProtocolException and Update Error Logs * Fix indentation, checkstyle errors
1 parent 933de30 commit 60171e3

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

aggregator-microservices/aggregator-service/src/main/java/com/iluwatar/aggregator/microservices/ProductInformationClientImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323
package com.iluwatar.aggregator.microservices;
2424

25+
import org.apache.http.client.ClientProtocolException;
2526
import org.apache.http.client.methods.CloseableHttpResponse;
2627
import org.apache.http.client.methods.HttpGet;
2728
import org.apache.http.impl.client.CloseableHttpClient;
@@ -49,8 +50,10 @@ public String getProductTitle() {
4950
try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) {
5051
response = EntityUtils.toString(httpResponse.getEntity());
5152
}
52-
} catch (IOException e) {
53-
LOGGER.error("Exception caught.", e);
53+
} catch (ClientProtocolException cpe) {
54+
LOGGER.error("ClientProtocolException Occured", cpe);
55+
} catch (IOException ioe) {
56+
LOGGER.error("IOException Occurred", ioe);
5457
}
5558
return response;
5659
}

aggregator-microservices/aggregator-service/src/main/java/com/iluwatar/aggregator/microservices/ProductInventoryClientImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323
package com.iluwatar.aggregator.microservices;
2424

25+
import org.apache.http.client.ClientProtocolException;
2526
import org.apache.http.client.methods.CloseableHttpResponse;
2627
import org.apache.http.client.methods.HttpGet;
2728
import org.apache.http.impl.client.CloseableHttpClient;
@@ -49,8 +50,10 @@ public int getProductInventories() {
4950
try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) {
5051
response = EntityUtils.toString(httpResponse.getEntity());
5152
}
52-
} catch (IOException e) {
53-
LOGGER.error("Exception caught.", e);
53+
} catch (ClientProtocolException cpe) {
54+
LOGGER.error("ClientProtocolException Occured", cpe);
55+
} catch (IOException ioe) {
56+
LOGGER.error("IOException Occurred", ioe);
5457
}
5558
return Integer.parseInt(response);
5659
}

0 commit comments

Comments
 (0)