public void handleError(HttpCommand command, HttpResponse response) { Exception exception = new HttpResponseException(command, response); try { byte[] data = closeClientButKeepContentStream(response); String message = data != null ? new String(data) : null; if (message != null) { exception = new HttpResponseException(command, response, message); if (message.indexOf("ErrorResponse") != -1) { AWSError error = factory.create(handlers.get()).parse(message); exception = refineException(new AWSResponseException(command, response, error)); } else if (message.indexOf("InvalidChangeBatch") != -1) { ImmutableList<String> errors = factory.create(batchHandlers.get()).parse(message); exception = new InvalidChangeBatchException(errors, new HttpResponseException(command, response)); } } } finally { releasePayload(response); command.setException(exception); } }
@Test public void testInvalidChangeBatchException() throws IOException { HttpResponse response = HttpResponse.builder().statusCode(BAD_REQUEST.getStatusCode()) .payload(payloadFromResource("/invalid_change_batch.xml")).build(); function.handleError(command, response); InvalidChangeBatchException exception = InvalidChangeBatchException.class.cast(command.getException()); assertEquals(exception.getMessages(), ImmutableSet.of( "Tried to create resource record set duplicate.example.com. type A, but it already exists", "Tried to delete resource record set noexist.example.com. type A, but it was not found")); }
@Test public void testInvalidChangeBatchException() throws IOException { HttpResponse response = HttpResponse.builder().statusCode(BAD_REQUEST.getStatusCode()) .payload(payloadFromResource("/invalid_change_batch.xml")).build(); function.handleError(command, response); InvalidChangeBatchException exception = InvalidChangeBatchException.class.cast(command.getException()); assertEquals(exception.getMessages(), ImmutableSet.of( "Tried to create resource record set duplicate.example.com. type A, but it already exists", "Tried to delete resource record set noexist.example.com. type A, but it was not found")); }
public void handleError(HttpCommand command, HttpResponse response) { Exception exception = new HttpResponseException(command, response); try { byte[] data = closeClientButKeepContentStream(response); String message = data != null ? new String(data) : null; if (message != null) { exception = new HttpResponseException(command, response, message); if (message.indexOf("ErrorResponse") != -1) { AWSError error = factory.create(handlers.get()).parse(message); exception = refineException(new AWSResponseException(command, response, error)); } else if (message.indexOf("InvalidChangeBatch") != -1) { ImmutableList<String> errors = factory.create(batchHandlers.get()).parse(message); exception = new InvalidChangeBatchException(errors, new HttpResponseException(command, response)); } } } finally { releasePayload(response); command.setException(exception); } }
public void handleError(HttpCommand command, HttpResponse response) { Exception exception = new HttpResponseException(command, response); try { byte[] data = closeClientButKeepContentStream(response); String message = data != null ? new String(data) : null; if (message != null) { exception = new HttpResponseException(command, response, message); if (message.indexOf("ErrorResponse") != -1) { AWSError error = factory.create(handlers.get()).parse(message); exception = refineException(new AWSResponseException(command, response, error)); } else if (message.indexOf("InvalidChangeBatch") != -1) { ImmutableList<String> errors = factory.create(batchHandlers.get()).parse(message); exception = new InvalidChangeBatchException(errors, new HttpResponseException(command, response)); } } } finally { releasePayload(response); command.setException(exception); } }
public void handleError(HttpCommand command, HttpResponse response) { Exception exception = new HttpResponseException(command, response); try { byte[] data = closeClientButKeepContentStream(response); String message = data != null ? new String(data) : null; if (message != null) { exception = new HttpResponseException(command, response, message); if (message.indexOf("ErrorResponse") != -1) { AWSError error = factory.create(handlers.get()).parse(message); exception = refineException(new AWSResponseException(command, response, error)); } else if (message.indexOf("InvalidChangeBatch") != -1) { ImmutableList<String> errors = factory.create(batchHandlers.get()).parse(message); exception = new InvalidChangeBatchException(errors, new HttpResponseException(command, response)); } } } finally { releasePayload(response); command.setException(exception); } }