From dfb9c8204ede00fdd1e0765b695f7022fac85406 Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Tue, 25 Jul 2023 15:36:54 +0300 Subject: [PATCH] Add useful messages for missing parameters in Stats API. --- .../controllers/BulkImportController.java | 2 +- .../controllers/StatsController.java | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/openaire/urls_controller/controllers/BulkImportController.java b/src/main/java/eu/openaire/urls_controller/controllers/BulkImportController.java index f904d0a..9916d82 100644 --- a/src/main/java/eu/openaire/urls_controller/controllers/BulkImportController.java +++ b/src/main/java/eu/openaire/urls_controller/controllers/BulkImportController.java @@ -74,7 +74,7 @@ public class BulkImportController { private static final Pattern LAST_DIR_REGEX = Pattern.compile("^.*/([^/]+/)$"); - // THis method shows the parameters which are missing when dealing with the bulk-import API. + // This method shows the parameters which are missing when dealing with the bulk-import API. // Spring Boot does not show any specific messages to the user (like stacktraces), for security reasons. @ExceptionHandler(MissingServletRequestParameterException.class) public ResponseEntity handleMissingParams(MissingServletRequestParameterException ex) { diff --git a/src/main/java/eu/openaire/urls_controller/controllers/StatsController.java b/src/main/java/eu/openaire/urls_controller/controllers/StatsController.java index 07201be..6ba555b 100644 --- a/src/main/java/eu/openaire/urls_controller/controllers/StatsController.java +++ b/src/main/java/eu/openaire/urls_controller/controllers/StatsController.java @@ -8,10 +8,8 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.MissingServletRequestParameterException; +import org.springframework.web.bind.annotation.*; /** @@ -27,6 +25,14 @@ public class StatsController { private StatsService statsService; + // This method shows the parameters which are missing when dealing with the bulk-import API. + // Spring Boot does not show any specific messages to the user (like stacktraces), for security reasons. + @ExceptionHandler(MissingServletRequestParameterException.class) + public ResponseEntity handleMissingParams(MissingServletRequestParameterException ex) { + return ResponseEntity.badRequest().body(String.format("Missing parameter: %s\n", ex.getParameterName())); + } + + /** * This endpoint returns the total number of payloads existing in the database, independently of the way they were aggregated. * This includes the payloads created by other pieces of software, before the PDF-Aggregation-Service was created.