Yuta HIGUCHI
Committed by Pavlin Radoslavov

DatabaseClient: check CopyCat response for errors

Change-Id: I49e46bd78293a4ca0f363a6b97e0995e46c05027
...@@ -16,6 +16,7 @@ import java.util.concurrent.TimeoutException; ...@@ -16,6 +16,7 @@ import java.util.concurrent.TimeoutException;
16 import net.kuujo.copycat.cluster.Member; 16 import net.kuujo.copycat.cluster.Member;
17 import net.kuujo.copycat.cluster.TcpMember; 17 import net.kuujo.copycat.cluster.TcpMember;
18 import net.kuujo.copycat.event.LeaderElectEvent; 18 import net.kuujo.copycat.event.LeaderElectEvent;
19 +import net.kuujo.copycat.protocol.Response.Status;
19 import net.kuujo.copycat.protocol.SubmitRequest; 20 import net.kuujo.copycat.protocol.SubmitRequest;
20 import net.kuujo.copycat.protocol.SubmitResponse; 21 import net.kuujo.copycat.protocol.SubmitResponse;
21 import net.kuujo.copycat.spi.protocol.ProtocolClient; 22 import net.kuujo.copycat.spi.protocol.ProtocolClient;
...@@ -107,7 +108,11 @@ public class DatabaseClient implements ClusterMessageHandler { ...@@ -107,7 +108,11 @@ public class DatabaseClient implements ClusterMessageHandler {
107 log.debug("Sent {} to {}", request, currentLeader); 108 log.debug("Sent {} to {}", request, currentLeader);
108 109
109 try { 110 try {
110 - return (T) submitResponse.get(TIMEOUT_MS, TimeUnit.MILLISECONDS).result(); 111 + final SubmitResponse response = submitResponse.get(TIMEOUT_MS, TimeUnit.MILLISECONDS);
112 + if (response.status() != Status.OK) {
113 + throw new DatabaseException(response.error());
114 + }
115 + return (T) response.result();
111 } catch (ExecutionException | InterruptedException e) { 116 } catch (ExecutionException | InterruptedException e) {
112 throw new DatabaseException(e); 117 throw new DatabaseException(e);
113 } catch (TimeoutException e) { 118 } catch (TimeoutException e) {
......