Fix: detection of network exceptions, merge duplicate HTTPRequest functions
This commit is contained in:
@@ -434,11 +434,14 @@ public class ServerRequest extends Thread {
|
||||
catch (SheepItException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (NoRouteToHostException e) {
|
||||
throw new SheepItServerDown();
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
throw new SheepItServerDown();
|
||||
catch (IOException e) {
|
||||
if (e.getCause() instanceof NoRouteToHostException || e.getCause() instanceof UnknownHostException) {
|
||||
throw new SheepItServerDown();
|
||||
}
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
throw new SheepItException("error requestJob: unknown IO exception " + e + " stacktrace: " + sw.toString());
|
||||
}
|
||||
catch (Exception e) {
|
||||
StringWriter sw = new StringWriter();
|
||||
@@ -458,30 +461,7 @@ public class ServerRequest extends Thread {
|
||||
}
|
||||
|
||||
public Response HTTPRequest(HttpUrl.Builder httpUrlBuilder, RequestBody data_) throws IOException {
|
||||
String url = httpUrlBuilder.build().toString();
|
||||
Request.Builder builder = new Request.Builder().addHeader("User-Agent", HTTP_USER_AGENT).url(url);
|
||||
|
||||
this.log.debug("Server::HTTPRequest url(" + url + ")");
|
||||
|
||||
if (data_ != null) {
|
||||
builder.post(data_);
|
||||
}
|
||||
|
||||
Request request = builder.build();
|
||||
|
||||
try {
|
||||
Response response = httpClient.newCall(request).execute();
|
||||
|
||||
if (response.isSuccessful() == false) {
|
||||
this.log.error("Received unsuccessful HTTP response " + response);
|
||||
}
|
||||
|
||||
this.lastRequestTime = new Date().getTime();
|
||||
return response;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IOException("Unexpected response from HTTP Stack" + e.getMessage());
|
||||
}
|
||||
return HTTPRequest(httpUrlBuilder, data_, false);
|
||||
}
|
||||
|
||||
public Response HTTPRequest(HttpUrl.Builder httpUrlBuilder, RequestBody data_, boolean checkIsSuccessful) throws IOException {
|
||||
@@ -507,10 +487,10 @@ public class ServerRequest extends Thread {
|
||||
return response;
|
||||
}
|
||||
catch (ConnectException e) {
|
||||
throw new ConnectException("Unexpected response from HTTP Stack" + e.getMessage());
|
||||
throw new ConnectException("Unexpected response from HTTP Stack " + e.getMessage());
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IOException("Unexpected response from HTTP Stack" + e.getMessage());
|
||||
throw new IOException("Unexpected response from HTTP Stack " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user