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.
This commit is contained in:
prachi 2012-05-21 18:28:25 -07:00
parent 704683d1f0
commit 1c1c663e34
1 changed files with 10 additions and 1 deletions

View File

@ -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();