} else {
statusCode = statusLine.getStatusCode();
reasonPhrase = statusLine.getReasonPhrase();
}
HttpResponse response = createResponse(method, request, apacheHttpResponse);
AmazonServiceException exception = null;
try {
exception = errorResponseHandler.handle(response);
if (requestLog.isDebugEnabled())
requestLog.debug("Received error response: " + exception);
} catch (Exception e) {
// If the errorResponseHandler doesn't work, then check for error
// responses that don't have any content
if (statusCode == 413) {
exception = new AmazonServiceException("Request entity too large");
exception.setServiceName(request.getServiceName());
exception.setStatusCode(statusCode);
exception.setErrorType(ErrorType.Client);
exception.setErrorCode("Request entity too large");
} else if (statusCode == 503
&& "Service Unavailable".equalsIgnoreCase(reasonPhrase)) {
exception = new AmazonServiceException("Service unavailable");
exception.setServiceName(request.getServiceName());
exception.setStatusCode(statusCode);
exception.setErrorType(ErrorType.Service);
exception.setErrorCode("Service unavailable");
} else if (e instanceof IOException) {
throw (IOException) e;
} else {
String errorMessage = "Unable to unmarshall error response ("
+ e.getMessage() + "). Response Code: "
+ (statusLine == null ? "None" : statusCode)
+ ", Response Text: " + reasonPhrase;
throw new AmazonClientException(errorMessage, e);
}
}
exception.setStatusCode(statusCode);
exception.setServiceName(request.getServiceName());
exception.fillInStackTrace();
return exception;
}