mirror of https://github.com/apache/jclouds.git
refactored aws error handler to provide the http content even when it isn't parsable (ex. returned in html
This commit is contained in:
parent
02d1ec664e
commit
8849e2793a
|
@ -66,14 +66,13 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler {
|
||||||
|
|
||||||
public void handleError(HttpCommand command, HttpResponse response) {
|
public void handleError(HttpCommand command, HttpResponse response) {
|
||||||
HttpRequest request = command.getRequest();
|
HttpRequest request = command.getRequest();
|
||||||
Exception exception = new HttpResponseException(command, response);
|
Exception exception = null;
|
||||||
try {
|
try {
|
||||||
AWSError error = null;
|
AWSError error = null;
|
||||||
String message = null;
|
String message = null;
|
||||||
if (response.getPayload() != null) {
|
if (response.getPayload() != null) {
|
||||||
String contentType = response.getPayload().getContentMetadata().getContentType();
|
String contentType = response.getPayload().getContentMetadata().getContentType();
|
||||||
if (contentType != null
|
if (contentType != null && (contentType.indexOf("xml") != -1 || contentType.indexOf("unknown") != -1)) {
|
||||||
&& (contentType.indexOf("xml") != -1 || contentType.indexOf("unknown") != -1)) {
|
|
||||||
error = utils.parseAWSErrorFromContent(request, response);
|
error = utils.parseAWSErrorFromContent(request, response);
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
message = error.getMessage();
|
message = error.getMessage();
|
||||||
|
@ -86,16 +85,17 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
message = message != null ? message : String.format("%s -> %s", request.getRequestLine(), response
|
message = message != null ? message : String.format("%s -> %s", request.getRequestLine(),
|
||||||
.getStatusLine());
|
response.getStatusLine());
|
||||||
|
if (exception == null)
|
||||||
|
exception = new HttpResponseException(command, response, message);
|
||||||
switch (response.getStatusCode()) {
|
switch (response.getStatusCode()) {
|
||||||
case 400:
|
case 400:
|
||||||
if (error != null && error.getCode() != null
|
if (error != null && error.getCode() != null
|
||||||
&& (error.getCode().endsWith(".NotFound") || error.getCode().endsWith(".Unknown")))
|
&& (error.getCode().endsWith(".NotFound") || error.getCode().endsWith(".Unknown")))
|
||||||
exception = new ResourceNotFoundException(message, exception);
|
exception = new ResourceNotFoundException(message, exception);
|
||||||
else if ((error != null && error.getCode() != null && (error.getCode().equals("IncorrectState") || error
|
else if ((error != null && error.getCode() != null && (error.getCode().equals("IncorrectState") || error
|
||||||
.getCode().endsWith(".Duplicate")))
|
.getCode().endsWith(".Duplicate"))) || (message != null && message.indexOf("already exists") != -1))
|
||||||
|| (message != null && message.indexOf("already exists") != -1))
|
|
||||||
exception = new IllegalStateException(message, exception);
|
exception = new IllegalStateException(message, exception);
|
||||||
else if (error != null && error.getCode() != null && error.getCode().equals("AuthFailure"))
|
else if (error != null && error.getCode() != null && error.getCode().equals("AuthFailure"))
|
||||||
exception = new AuthorizationException(command.getRequest(), message);
|
exception = new AuthorizationException(command.getRequest(), message);
|
||||||
|
|
Loading…
Reference in New Issue