Java: Added a session handler with authentication capability.
[doldaconnect.git] / lib / java / dolda / dolcon / ResponseException.java
diff --git a/lib/java/dolda/dolcon/ResponseException.java b/lib/java/dolda/dolcon/ResponseException.java
new file mode 100644 (file)
index 0000000..d218b8e
--- /dev/null
@@ -0,0 +1,26 @@
+package dolda.dolcon;
+
+import dolda.dolcon.protocol.Response;
+
+public class ResponseException extends ProtocolException {
+    Response resp;
+    int expected;
+    
+    public ResponseException(Response resp, int expected) {
+       super("Unhandled DC protocol response (" + resp.code + " != " + expected + ")");
+       this.resp = resp;
+       this.expected = expected;
+    }
+    
+    public ResponseException(String msg, Response resp, int expected) {
+       super(msg);
+       this.resp = resp;
+       this.expected = expected;
+    }
+    
+    public static Response check(Response resp, int expect) throws ResponseException {
+       if(resp.code != expect)
+           throw(new ResponseException(resp, expect));
+       return(resp);
+    }
+}