protected Handler<Response> createErrorHandler(final String text) {
return new Handler<Response>() {
public void handle(Response event) throws Exception {
if (event instanceof ExceptionResponse) {
ExceptionResponse exceptionResponse = (ExceptionResponse)event;
Throwable exception = exceptionResponse.getException();
LOG.error("Failed to " + text + ". Reason: " + exception, exception);
} else if (LOG.isDebugEnabled()) {
LOG.debug("Completed " + text);
}
}