Fix for Issue #549 : Update Exception Handling Code in Aggregator Microservice (#958)

*  Fix for Issue##549

Catch ClientProtocolException and Update Error Logs

* Fix indentation, checkstyle errors
This commit is contained in:
Arpit Jain authored and Ilkka Seppälä committed 2019-10-06 18:27:39 +03:00
1 parent 933de30d42
commit 60171e3c87
2 files changed
+10 -4

No files matched your search

@@ -22,6 +22,7 @@
*/ */
package com.iluwatar.aggregator.microservices; package com.iluwatar.aggregator.microservices;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
@@ -49,8 +50,10 @@ public class ProductInformationClientImpl implements ProductInformationClient {
try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) { try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) {
response = EntityUtils.toString(httpResponse.getEntity()); response = EntityUtils.toString(httpResponse.getEntity());
} }
} catch (IOException e) { } catch (ClientProtocolException cpe) {
LOGGER.error("Exception caught.", e); LOGGER.error("ClientProtocolException Occured", cpe);
} catch (IOException ioe) {
LOGGER.error("IOException Occurred", ioe);
} }
return response; return response;
} }
@@ -22,6 +22,7 @@
*/ */
package com.iluwatar.aggregator.microservices; package com.iluwatar.aggregator.microservices;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
@@ -49,8 +50,10 @@ public class ProductInventoryClientImpl implements ProductInventoryClient {
try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) { try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) {
response = EntityUtils.toString(httpResponse.getEntity()); response = EntityUtils.toString(httpResponse.getEntity());
} }
} catch (IOException e) { } catch (ClientProtocolException cpe) {
LOGGER.error("Exception caught.", e); LOGGER.error("ClientProtocolException Occured", cpe);
} catch (IOException ioe) {
LOGGER.error("IOException Occurred", ioe);
} }
return Integer.parseInt(response); return Integer.parseInt(response);
} }