| 1 | package dolda.dolcon; |
| 2 | |
| 3 | import dolda.dolcon.protocol.Response; |
| 4 | |
| 5 | public class ResponseException extends ProtocolException { |
| 6 | Response resp; |
| 7 | int expected; |
| 8 | |
| 9 | public ResponseException(Response resp, int expected) { |
| 10 | super("Unhandled DC protocol response (" + resp.code + " != " + expected + ")"); |
| 11 | this.resp = resp; |
| 12 | this.expected = expected; |
| 13 | } |
| 14 | |
| 15 | public ResponseException(String msg, Response resp, int expected) { |
| 16 | super(msg); |
| 17 | this.resp = resp; |
| 18 | this.expected = expected; |
| 19 | } |
| 20 | |
| 21 | public static Response check(Response resp, int expect) throws ResponseException { |
| 22 | if(resp.code != expect) |
| 23 | throw(new ResponseException(resp, expect)); |
| 24 | return(resp); |
| 25 | } |
| 26 | } |