Repository: iluwatar/java-design-patterns
Issue: "Aggregator microservices"  design pattern doesn't show exception handling 
Labels: type: enhancement
info: good first issue
epic: code quality

"Aggregator microservices"  design pattern doesn't show how exception handling would be done if the one or multiple services used are down and how client calling the aggregator microservice would cope in this situation.

Issue comments:
Can't we consider 

`    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
      HttpGet httpGet = new HttpGet("http://localhost:51515/information");
      try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) {
        response = EntityUtils.toString(httpResponse.getEntity());
      }
    } catch (IOException e) {
      LOGGER.error("Exception caught.", e);
    }`

in com.iluwatar.aggregator.microservices.ProductInformationClientImpl as example of fallback strategy ([https://blogs.oracle.com/developers/getting-started-with-microservices-part-three](url))?
Or do i not understand the task?
Has this issue been resolved?
@ddunig2 I don't see a PR against this. If you want to resolve, you can go ahead.
Hi, I am raising a PR for this, where ClientProtocolException is caught and  the error log statements are updated.
https://github.com/iluwatar/java-design-patterns/pull/958
Exception handling was improved, but the original issue still remains unsolved
Under investigation by @jarpit96 
@iluwatar @ddunig2 To implement fallback pattern in Aggregator Service, is returning default literals/constants sufficient ?
I would probably display an error message to the user in case one of the microservices does not respond or some other fault occurs
#971
I have added fall backs in Aggregator Service when other microservices fail. Default error messages (Product Title and Inventory) are returned to the user.

Pull request review comments:

Patch that resolved the issue:
diff --git a/aggregator-microservices/aggregator-service/src/main/java/com/iluwatar/aggregator/microservices/ProductInformationClientImpl.java b/aggregator-microservices/aggregator-service/src/main/java/com/iluwatar/aggregator/microservices/ProductInformationClientImpl.java
index 16849d529386..131fbf8695cd 100644
--- a/aggregator-microservices/aggregator-service/src/main/java/com/iluwatar/aggregator/microservices/ProductInformationClientImpl.java
+++ b/aggregator-microservices/aggregator-service/src/main/java/com/iluwatar/aggregator/microservices/ProductInformationClientImpl.java
@@ -22,6 +22,7 @@
  */
 package com.iluwatar.aggregator.microservices;
 
+import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.impl.client.CloseableHttpClient;
@@ -49,8 +50,10 @@ public String getProductTitle() {
       try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) {
         response = EntityUtils.toString(httpResponse.getEntity());
       }
-    } catch (IOException e) {
-      LOGGER.error("Exception caught.", e);
+    } catch (ClientProtocolException cpe) {
+      LOGGER.error("ClientProtocolException Occured", cpe);
+    } catch (IOException ioe) {
+      LOGGER.error("IOException Occurred", ioe);
     }
     return response;
   }
diff --git a/aggregator-microservices/aggregator-service/src/main/java/com/iluwatar/aggregator/microservices/ProductInventoryClientImpl.java b/aggregator-microservices/aggregator-service/src/main/java/com/iluwatar/aggregator/microservices/ProductInventoryClientImpl.java
index 89f1a25e0580..780dccb78e20 100644
--- a/aggregator-microservices/aggregator-service/src/main/java/com/iluwatar/aggregator/microservices/ProductInventoryClientImpl.java
+++ b/aggregator-microservices/aggregator-service/src/main/java/com/iluwatar/aggregator/microservices/ProductInventoryClientImpl.java
@@ -22,6 +22,7 @@
  */
 package com.iluwatar.aggregator.microservices;
 
+import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.impl.client.CloseableHttpClient;
@@ -49,8 +50,10 @@ public int getProductInventories() {
       try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) {
         response = EntityUtils.toString(httpResponse.getEntity());
       }
-    } catch (IOException e) {
-      LOGGER.error("Exception caught.", e);
+    } catch (ClientProtocolException cpe) {
+      LOGGER.error("ClientProtocolException Occured", cpe);
+    } catch (IOException ioe) {
+      LOGGER.error("IOException Occurred", ioe);
     }
     return Integer.parseInt(response);
   }


Test patch: