Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add HttpIOExcption to enable the extraction of responseCode #31

Open
wants to merge 2 commits into from

2 participants

@timp21337

Rather than parse the exception message I have created a new Exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 16, 2013
  1. @timp
Commits on Oct 17, 2013
  1. @timp

    Add toString, copying Gary Leeson

    timp authored
This page is out of date. Refresh to see the latest.
View
4 src/main/java/us/monoid/web/AbstractResource.java
@@ -56,8 +56,8 @@ void fill(URLConnection anUrlConnection) throws IOException {
// close the errorstream
es.close();
- throw new IOException("Error while reading from " + conn.getRequestMethod() + ": [" + conn.getResponseCode() + "] "
- + conn.getResponseMessage() + "\n" + new String(baos.toByteArray(), "UTF-8"), e);
+ throw new HttpIOException(conn.getRequestMethod(), conn.getResponseCode(), conn.getResponseMessage(),
+ new String(baos.toByteArray(), "UTF-8"), e);
} else {
throw e;
}
View
55 src/main/java/us/monoid/web/HttpIOException.java
@@ -0,0 +1,55 @@
+package us.monoid.web;
+
+import java.io.IOException;
+
+/**
+ * @author timp21337
+ * @since 2103-10-15
+ */
+public class HttpIOException extends IOException {
+
+ private String requestMethod;
+ private int responseCode;
+ private String responseMessage;
+ private String content;
+
+ public HttpIOException(String requestMethod, int responseCode,
+ String responseMessage, String content, IOException e) {
+ super(e);
+ this.requestMethod = requestMethod;
+ this.responseCode = responseCode;
+ this.responseMessage = responseMessage;
+ this.content = content;
+ }
+
+ public String getRequestMethod() {
+ return requestMethod;
+ }
+ public int getResponseCode() {
+ return responseCode;
+ }
+ public String getResponseMessage() {
+ return responseMessage;
+ }
+ public String getContent() {
+ return content;
+ }
+
+ @Override
+ public String getMessage() {
+ return "Error while reading from " + getRequestMethod()
+ + ": [" + getResponseCode() + "] "
+ + getResponseMessage() + "\n"
+ + getContent();
+ }
+
+ @Override
+ public String toString() {
+ return "HttpIOException{" +
+ "requestMethod='" + requestMethod + '\'' +
+ ", responseCode=" + responseCode +
+ ", responseMessage='" + responseMessage + '\'' +
+ ", content='" + content + '\'' +
+ '}';
+ }
+}
Something went wrong with that request. Please try again.