From c283cb43653bb1fbcdc702d6d4bccbba92f36b1d Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Mon, 16 Jan 2023 15:22:32 +0200 Subject: [PATCH] Improve exception-handling in "AssignmentsHandler.postWorkerReport()". --- .../urls_worker/util/AssignmentsHandler.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/openaire/urls_worker/util/AssignmentsHandler.java b/src/main/java/eu/openaire/urls_worker/util/AssignmentsHandler.java index 3217ec1..8c72a5c 100644 --- a/src/main/java/eu/openaire/urls_worker/util/AssignmentsHandler.java +++ b/src/main/java/eu/openaire/urls_worker/util/AssignmentsHandler.java @@ -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 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.