mirror of https://github.com/apache/jclouds.git
correct exception when out of ips
This commit is contained in:
parent
75604da8f2
commit
4225b5b49b
|
@ -35,6 +35,7 @@ import org.jclouds.http.HttpResponse;
|
|||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.InsufficientResourcesException;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.util.Strings2;
|
||||
|
||||
|
@ -94,19 +95,21 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler {
|
|||
|
||||
protected Exception refineException(HttpCommand command, HttpResponse response, Exception exception, AWSError error,
|
||||
String message) {
|
||||
String errorCode = (error != null && error.getCode() != null) ? error.getCode() : null;
|
||||
switch (response.getStatusCode()) {
|
||||
case 400:
|
||||
if (error != null && error.getCode() != null && (error.getCode().equals("UnsupportedOperation")))
|
||||
if ("UnsupportedOperation".equals(errorCode))
|
||||
exception = new UnsupportedOperationException(message, exception);
|
||||
if (error != null && error.getCode() != null
|
||||
&& (error.getCode().endsWith("NotFound") || error.getCode().endsWith(".Unknown")))
|
||||
else if ("AddressLimitExceeded".equals(errorCode))
|
||||
exception = new InsufficientResourcesException(message, exception);
|
||||
else if (errorCode != null && (errorCode.endsWith("NotFound") || errorCode.endsWith(".Unknown")))
|
||||
exception = new ResourceNotFoundException(message, exception);
|
||||
else if ((error != null && error.getCode() != null && (error.getCode().equals("IncorrectState") || error
|
||||
.getCode().endsWith(".Duplicate")
|
||||
| error.getCode().endsWith(".InUse")))
|
||||
else if ("IncorrectState".equals(errorCode)
|
||||
|| (errorCode != null && (error.getCode().endsWith(".Duplicate") | error.getCode().endsWith(
|
||||
".InUse")))
|
||||
|| (message != null && (message.indexOf("already exists") != -1 || message.indexOf("is in use") != -1)))
|
||||
exception = new IllegalStateException(message, exception);
|
||||
else if (error != null && error.getCode() != null && error.getCode().equals("AuthFailure"))
|
||||
else if ("AuthFailure".equals(errorCode))
|
||||
exception = new AuthorizationException(message, exception);
|
||||
else if (message != null
|
||||
&& (message.indexOf("Invalid id") != -1 || message.indexOf("Failed to bind") != -1))
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.jclouds.http.HttpResponse;
|
|||
import org.jclouds.http.functions.config.SaxParserModule;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.InsufficientResourcesException;
|
||||
import org.jclouds.rest.RequestSigner;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.util.Strings2;
|
||||
|
@ -73,6 +74,17 @@ public class ParseAWSErrorFromXmlContentTest {
|
|||
assertCodeMakes("POST", URI.create("https://ec2.us-west-1.amazonaws.com/"), 400, "",
|
||||
"<Error><Code>UnsupportedOperation</Code></Error>", UnsupportedOperationException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test400WithAddressLimitExceededCodeMakesInsufficientResourcesException() {
|
||||
assertCodeMakes(
|
||||
"POST",
|
||||
URI.create("https://ec2.us-east-1.amazonaws.com/"),
|
||||
400,
|
||||
"",
|
||||
"<Response><Errors><Error><Code>AddressLimitExceeded</Code><Message>Too many addresses allocated</Message></Error></Errors><RequestID>c14f531a-cc35-4b48-8149-2655c7e6dc76</RequestID></Response>",
|
||||
InsufficientResourcesException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test400WithInUseCodeSetsIllegalStateException() {
|
||||
|
|
Loading…
Reference in New Issue