Commit 1efb258b authored by Lukas Jelonek's avatar Lukas Jelonek
Browse files

Improved error message when a url is not available anymore

parent 26bd1f7d
......@@ -20,8 +20,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.io.IOUtils;
/**
......@@ -44,16 +42,15 @@ public abstract class AbstractResource implements Resource {
@Override
public String getResourceText() {
try {
HttpURLConnection openConnection = (HttpURLConnection) uri.toURL().openConnection();
openConnection.connect();
int responseCode = openConnection.getResponseCode();
openConnection.disconnect();
HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
connection.connect();
int responseCode = connection.getResponseCode();
connection.disconnect();
if (responseCode >= 400) {
throw new UnsupportedOperationException("Invalid url");
throw new UnsupportedOperationException("Can't access " + uri + " Return code [" + responseCode + "]");
}
} catch (IOException ex) {
Logger.getLogger(AbstractResource.class.getName()).log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
throw new RuntimeException("Error accessing " + uri, ex);
}
try (InputStream stream = uri.toURL().openStream()) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment