Skip to content

Commit

Permalink
better handling of https errors
Browse files Browse the repository at this point in the history
- the content of http error messages is now displayed
- slighly bigger connection timeout
  • Loading branch information
mwarning committed Apr 6, 2020
1 parent 1cbe235 commit 1724413
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,22 @@ public void run() {
}

HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setConnectTimeout(2000);
con.setConnectTimeout(2500);

if (!setup.method.isEmpty()) {
con.setRequestMethod(setup.method.toUpperCase());
}

String result = Utils.readInputStreamWithTimeout(con.getInputStream(), 50000, 2000);

if (con.getResponseCode() == 200) {
String result = Utils.readInputStreamWithTimeout(con.getInputStream(), 50000, 2500);
this.listener.onTaskResult(setup.getId(), ReplyCode.SUCCESS, result);
} else {
this.listener.onTaskResult(setup.getId(), ReplyCode.REMOTE_ERROR, con.getResponseMessage());
String result = Utils.readInputStreamWithTimeout(con.getErrorStream(), 50000, 2500);
if (!Utils.isEmpty(result)) {
this.listener.onTaskResult(setup.getId(), ReplyCode.REMOTE_ERROR, result);
} else {
this.listener.onTaskResult(setup.getId(), ReplyCode.REMOTE_ERROR, con.getResponseMessage());
}
}
} catch (MalformedURLException mue) {
this.listener.onTaskResult(setup.getId(), ReplyCode.LOCAL_ERROR, "Malformed URL.");
Expand Down

0 comments on commit 1724413

Please sign in to comment.