refactored aws error handler to provide the http content even when it isn't parsable (ex. returned in html

This commit is contained in:
Adrian Cole 2010-11-07 01:50:07 +01:00
parent 02d1ec664e
commit 8849e2793a
1 changed files with 31 additions and 31 deletions

View File

@ -66,14 +66,13 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler {
public void handleError(HttpCommand command, HttpResponse response) {
HttpRequest request = command.getRequest();
Exception exception = new HttpResponseException(command, response);
Exception exception = null;
try {
AWSError error = null;
String message = null;
if (response.getPayload() != null) {
String contentType = response.getPayload().getContentMetadata().getContentType();
if (contentType != null
&& (contentType.indexOf("xml") != -1 || contentType.indexOf("unknown") != -1)) {
if (contentType != null && (contentType.indexOf("xml") != -1 || contentType.indexOf("unknown") != -1)) {
error = utils.parseAWSErrorFromContent(request, response);
if (error != null) {
message = error.getMessage();
@ -86,16 +85,17 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler {
}
}
}
message = message != null ? message : String.format("%s -> %s", request.getRequestLine(), response
.getStatusLine());
message = message != null ? message : String.format("%s -> %s", request.getRequestLine(),
response.getStatusLine());
if (exception == null)
exception = new HttpResponseException(command, response, message);
switch (response.getStatusCode()) {
case 400:
if (error != null && error.getCode() != null
&& (error.getCode().endsWith(".NotFound") || error.getCode().endsWith(".Unknown")))
exception = new ResourceNotFoundException(message, exception);
else if ((error != null && error.getCode() != null && (error.getCode().equals("IncorrectState") || error
.getCode().endsWith(".Duplicate")))
|| (message != null && message.indexOf("already exists") != -1))
.getCode().endsWith(".Duplicate"))) || (message != null && message.indexOf("already exists") != -1))
exception = new IllegalStateException(message, exception);
else if (error != null && error.getCode() != null && error.getCode().equals("AuthFailure"))
exception = new AuthorizationException(command.getRequest(), message);