Improve exception-handling in "AssignmentsHandler.postWorkerReport()".
This commit is contained in:
parent
d96d0c68cd
commit
c283cb4365
|
@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.HttpServerErrorException;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
|
@ -189,7 +190,7 @@ public class AssignmentsHandler {
|
|||
public static boolean postWorkerReport(Long assignmentRequestCounter)
|
||||
{
|
||||
String postUrl = UrlsWorkerApplication.controllerBaseUrl + "urls/addWorkerReport";
|
||||
logger.info("Going to post the WorkerReport of assignment_" + assignmentRequestCounter + " to the controller-server: " + postUrl);
|
||||
logger.info("Going to post the WorkerReport of assignments_" + assignmentRequestCounter + " to the controller-server: " + postUrl);
|
||||
try {
|
||||
ResponseEntity<String> responseEntity = restTemplate.postForEntity(postUrl, new WorkerReport(UrlsWorkerApplication.workerId, assignmentRequestCounter, urlReports), String.class);
|
||||
|
||||
|
@ -204,12 +205,15 @@ public class AssignmentsHandler {
|
|||
} else if ( responseCode == HttpStatus.MULTI_STATUS.value() ) {
|
||||
logger.warn("The submission of the WorkerReport of assignments_" + assignmentRequestCounter + " to the Controller was successful, but the full-texts' delivering failed!");
|
||||
return true;
|
||||
} else {
|
||||
logger.error("HTTP-Connection problem with the submission of the WorkerReport of assignment_" + assignmentRequestCounter + " to the Controller! Error-code was: " + responseCode);
|
||||
} else { // This does not include HTTP-5XX errors. For them an "HttpServerErrorException" is thrown.
|
||||
logger.error("HTTP-Connection problem with the submission of the WorkerReport of assignments_" + assignmentRequestCounter + " to the Controller! Error-code was: " + responseCode);
|
||||
return false;
|
||||
}
|
||||
} catch (HttpServerErrorException hsee) {
|
||||
logger.error("The Controller failed to handle the WorkerReport of assignments_" + assignmentRequestCounter + ": " + hsee.getMessage());
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
logger.error("Error when submitting the WorkerReport of assignment_" + assignmentRequestCounter + " to the Controller: ", e);
|
||||
logger.error("Error when submitting the WorkerReport of assignments_" + assignmentRequestCounter + " to the Controller: ", e);
|
||||
return false;
|
||||
} finally {
|
||||
urlReports.clear(); // Reset, without de-allocating.
|
||||
|
|
Loading…
Reference in New Issue