Add useful messages for missing parameters in Stats API.

This commit is contained in:
Lampros Smyrnaios 2023-07-25 15:36:54 +03:00
parent cde6063d63
commit dfb9c8204e
2 changed files with 11 additions and 5 deletions

View File

@ -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) {

View File

@ -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.