From 1c1c663e347f9c3db4c35d6d4f345636369c3189 Mon Sep 17 00:00:00 2001 From: prachi Date: Mon, 21 May 2012 18:28:25 -0700 Subject: [PATCH] CS-14661: Error handling should be imporved Changes: - Read the HttpURLConnection responseMessage. - If not found check if there is "X-Description" header that gives out a message - if not use a default error string with status code. --- awsapi/src/com/cloud/stack/CloudStackClient.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/awsapi/src/com/cloud/stack/CloudStackClient.java b/awsapi/src/com/cloud/stack/CloudStackClient.java index d8cabaf214a..ed04737a2ad 100644 --- a/awsapi/src/com/cloud/stack/CloudStackClient.java +++ b/awsapi/src/com/cloud/stack/CloudStackClient.java @@ -170,7 +170,16 @@ public class CloudStackClient { statusCode = ((HttpURLConnection)connect).getResponseCode(); if(statusCode >= 400) { logger.error("Cloud API call + [" + url.toString() + "] failed with status code: " + statusCode); - throw new IOException("CloudStack API call HTTP response error, HTTP status code: " + statusCode); + String errorMessage = ((HttpURLConnection)connect).getResponseMessage(); + if(errorMessage == null){ + errorMessage = connect.getHeaderField("X-Description"); + } + + if(errorMessage == null){ + errorMessage = "CloudStack API call HTTP response error, HTTP status code: " + statusCode; + } + + throw new IOException(errorMessage); } InputStream inputStream = connect.getInputStream();