mirror of https://github.com/apache/cloudstack.git
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:
parent
704683d1f0
commit
1c1c663e34
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue