Skip to content
This repository has been archived by the owner on Apr 1, 2019. It is now read-only.

Add HttpIOExcption to enable the extraction of responseCode #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/us/monoid/web/AbstractResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
55 changes: 55 additions & 0 deletions src/main/java/us/monoid/web/HttpIOException.java
Original file line number Diff line number Diff line change
@@ -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 + '\'' +
'}';
}
}