Throw a different exception type for unexpected http status codes

This commit is contained in:
Jeremy Lakeman 2018-05-23 10:50:09 +09:30
parent 0c5a84c305
commit b1fdf380f9
2 changed files with 19 additions and 2 deletions

View File

@ -65,8 +65,7 @@ public abstract class AbstractJsonList<T, E extends Exception> {
}
protected void handleResponseError() throws E, IOException, ServalDInterfaceException {
throw new ServalDFailureException("received unexpected HTTP Status "+
httpConnection.getResponseCode()+" " + httpConnection.getResponseMessage()+" from " + httpConnection.getURL());
throw new ServalDUnexpectedHttpStatus(httpConnection);
}
public void connect() throws IOException, ServalDInterfaceException, E {

View File

@ -0,0 +1,18 @@
package org.servalproject.servaldna;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
public class ServalDUnexpectedHttpStatus extends ServalDInterfaceException {
public final int responseCode;
public final String responseMessage;
public final URL url;
public ServalDUnexpectedHttpStatus(HttpURLConnection httpConnection) throws IOException {
super("received unexpected HTTP Status "+
httpConnection.getResponseCode()+" " + httpConnection.getResponseMessage()+" from " + httpConnection.getURL());
this.responseCode = httpConnection.getResponseCode();
this.responseMessage = httpConnection.getResponseMessage();
this.url = httpConnection.getURL();
}
}