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.http.HttpResponseException;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.rest.AuthorizationException;
|
import org.jclouds.rest.AuthorizationException;
|
||||||
|
import org.jclouds.rest.InsufficientResourcesException;
|
||||||
import org.jclouds.rest.ResourceNotFoundException;
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
import org.jclouds.util.Strings2;
|
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,
|
protected Exception refineException(HttpCommand command, HttpResponse response, Exception exception, AWSError error,
|
||||||
String message) {
|
String message) {
|
||||||
|
String errorCode = (error != null && error.getCode() != null) ? error.getCode() : null;
|
||||||
switch (response.getStatusCode()) {
|
switch (response.getStatusCode()) {
|
||||||
case 400:
|
case 400:
|
||||||
if (error != null && error.getCode() != null && (error.getCode().equals("UnsupportedOperation")))
|
if ("UnsupportedOperation".equals(errorCode))
|
||||||
exception = new UnsupportedOperationException(message, exception);
|
exception = new UnsupportedOperationException(message, exception);
|
||||||
if (error != null && error.getCode() != null
|
else if ("AddressLimitExceeded".equals(errorCode))
|
||||||
&& (error.getCode().endsWith("NotFound") || error.getCode().endsWith(".Unknown")))
|
exception = new InsufficientResourcesException(message, exception);
|
||||||
|
else if (errorCode != null && (errorCode.endsWith("NotFound") || errorCode.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 ("IncorrectState".equals(errorCode)
|
||||||
.getCode().endsWith(".Duplicate")
|
|| (errorCode != null && (error.getCode().endsWith(".Duplicate") | error.getCode().endsWith(
|
||||||
| error.getCode().endsWith(".InUse")))
|
".InUse")))
|
||||||
|| (message != null && (message.indexOf("already exists") != -1 || message.indexOf("is in use") != -1)))
|
|| (message != null && (message.indexOf("already exists") != -1 || message.indexOf("is in use") != -1)))
|
||||||
exception = new IllegalStateException(message, exception);
|
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);
|
exception = new AuthorizationException(message, exception);
|
||||||
else if (message != null
|
else if (message != null
|
||||||
&& (message.indexOf("Invalid id") != -1 || message.indexOf("Failed to bind") != -1))
|
&& (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.http.functions.config.SaxParserModule;
|
||||||
import org.jclouds.io.Payloads;
|
import org.jclouds.io.Payloads;
|
||||||
import org.jclouds.rest.AuthorizationException;
|
import org.jclouds.rest.AuthorizationException;
|
||||||
|
import org.jclouds.rest.InsufficientResourcesException;
|
||||||
import org.jclouds.rest.RequestSigner;
|
import org.jclouds.rest.RequestSigner;
|
||||||
import org.jclouds.rest.ResourceNotFoundException;
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
import org.jclouds.util.Strings2;
|
import org.jclouds.util.Strings2;
|
||||||
|
@ -74,6 +75,17 @@ public class ParseAWSErrorFromXmlContentTest {
|
||||||
"<Error><Code>UnsupportedOperation</Code></Error>", UnsupportedOperationException.class);
|
"<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
|
@Test
|
||||||
public void test400WithInUseCodeSetsIllegalStateException() {
|
public void test400WithInUseCodeSetsIllegalStateException() {
|
||||||
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "",
|
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "",
|
||||||
|
|
Loading…
Reference in New Issue