X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=lib%2Fjava%2Fdolda%2Fdolcon%2FResponseException.java;fp=lib%2Fjava%2Fdolda%2Fdolcon%2FResponseException.java;h=d218b8e9d6d47e5bdc5ffe14c9471c508746915c;hb=7131093cf84874bc7290c18cf34a3ae4d36cf2bd;hp=0000000000000000000000000000000000000000;hpb=59b214d63f3e51473177f573bdc4c8edaa08f9ea;p=doldaconnect.git diff --git a/lib/java/dolda/dolcon/ResponseException.java b/lib/java/dolda/dolcon/ResponseException.java new file mode 100644 index 0000000..d218b8e --- /dev/null +++ b/lib/java/dolda/dolcon/ResponseException.java @@ -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); + } +}