public ParseAWSErrorFromXmlContent(AWSUtils utils) {
this.utils = utils;
}
public void handleError(HttpCommand command, HttpResponse response) {
Exception exception = new HttpResponseException(command, response);
try {
AWSError error = null;
// it is important to always read fully and close streams
byte[] data = closeClientButKeepContentStream(response);
String message = data != null ? new String(data) : null;
if (response.getPayload() != null) {
String contentType = response.getPayload().getContentMetadata().getContentType();
if (contentType != null && (contentType.indexOf("xml") != -1 || contentType.indexOf("unknown") != -1)) {
error = utils.parseAWSErrorFromContent(command.getCurrentRequest(), response);
if (error != null) {
message = error.getMessage();
exception = new AWSResponseException(command, response, error);
} else {
exception = new HttpResponseException(command, response, message);
}
} else {
try {
message = Strings2.toString(response.getPayload());
exception = new HttpResponseException(command, response, message);
} catch (IOException e) {
}
}
}
message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(),