diff --git a/service/src/main/java/gov/nasa/pds/api/registry/controllers/ProductsController.java b/service/src/main/java/gov/nasa/pds/api/registry/controllers/ProductsController.java index 8ce58a71..0c31e496 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/controllers/ProductsController.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/controllers/ProductsController.java @@ -406,7 +406,7 @@ private PdsLidVid resolveIdentifierToLidvid(PdsProductIdentifier identifier) thr @Override public ResponseEntity productMembers( String identifier, List fields, Integer limit, List sort, List searchAfter) - throws NotFoundException, UnhandledException, SortSearchAfterMismatchException, MiscellaneousBadRequestException, + throws NotFoundException, UnhandledException, SortSearchAfterMismatchException, BadRequestException, AcceptFormatNotSupportedException{ try{ @@ -423,7 +423,7 @@ public ResponseEntity productMembers( searchRequestBuilder.matchMembersOfCollection(lidvid); searchRequestBuilder.onlyBasicProducts(); } else { - throw new MiscellaneousBadRequestException("productMembers endpoint is only valid for products with Product_Class '" + + throw new BadRequestException("productMembers endpoint is only valid for products with Product_Class '" + PdsProductClasses.Product_Bundle + "' or '" + PdsProductClasses.Product_Collection + "' (got '" + productClass + "')"); } @@ -449,7 +449,7 @@ public ResponseEntity productMembers( @Override public ResponseEntity productMembersMembers( String identifier, List fields, Integer limit, List sort, List searchAfter) - throws NotFoundException, UnhandledException, SortSearchAfterMismatchException, MiscellaneousBadRequestException, + throws NotFoundException, UnhandledException, SortSearchAfterMismatchException, BadRequestException, AcceptFormatNotSupportedException{ try{ @@ -463,7 +463,7 @@ public ResponseEntity productMembersMembers( searchRequestBuilder.matchMembersOfBundle(lidvid); searchRequestBuilder.onlyBasicProducts(); } else { - throw new MiscellaneousBadRequestException("productMembers endpoint is only valid for products with Product_Class '" + + throw new BadRequestException("productMembers endpoint is only valid for products with Product_Class '" + PdsProductClasses.Product_Bundle + "' (got '" + productClass + "')"); } @@ -524,7 +524,7 @@ private List resolveLidVidsFromProductField(PdsProductIdentifier iden @Override public ResponseEntity productMemberOf( String identifier, List fields, Integer limit, List sort, List searchAfter) - throws NotFoundException, UnhandledException, SortSearchAfterMismatchException, MiscellaneousBadRequestException, + throws NotFoundException, UnhandledException, SortSearchAfterMismatchException, BadRequestException, AcceptFormatNotSupportedException{ try{ @@ -538,7 +538,7 @@ public ResponseEntity productMemberOf( } else if (productClass.isBasicProduct()) { parentIds = resolveLidVidsFromProductField(lidvid, "ops:Provenance/ops:parent_collection_identifier"); } else { - throw new MiscellaneousBadRequestException("productMembersOf endpoint is not valid for products with Product_Class '" + + throw new BadRequestException("productMembersOf endpoint is not valid for products with Product_Class '" + PdsProductClasses.Product_Bundle + "' (got '" + productClass + "')"); } @@ -564,7 +564,7 @@ public ResponseEntity productMemberOf( @Override public ResponseEntity productMemberOfOf( String identifier, List fields, Integer limit, List sort, List searchAfter) - throws NotFoundException, UnhandledException, SortSearchAfterMismatchException, MiscellaneousBadRequestException, + throws NotFoundException, UnhandledException, SortSearchAfterMismatchException, BadRequestException, AcceptFormatNotSupportedException{ try{ @@ -577,7 +577,7 @@ public ResponseEntity productMemberOfOf( parentIds = resolveLidVidsFromProductField(lidvid, "ops:Provenance/ops:parent_bundle_identifier"); } else { // TODO: replace with enumeration of acceptable values later - throw new MiscellaneousBadRequestException("productMembersOf endpoint is not valid for products with Product_Class '" + + throw new BadRequestException("productMembersOf endpoint is not valid for products with Product_Class '" + PdsProductClasses.Product_Bundle + "' or '" + PdsProductClasses.Product_Collection + "' (got '" + productClass + "')"); } diff --git a/service/src/main/java/gov/nasa/pds/api/registry/controllers/RegistryApiResponseEntityExceptionHandler.java b/service/src/main/java/gov/nasa/pds/api/registry/controllers/RegistryApiResponseEntityExceptionHandler.java index 4caf77f4..2de03b14 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/controllers/RegistryApiResponseEntityExceptionHandler.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/controllers/RegistryApiResponseEntityExceptionHandler.java @@ -2,6 +2,8 @@ import java.util.Set; + +import gov.nasa.pds.api.registry.model.exceptions.*; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -9,13 +11,6 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.context.request.WebRequest; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; -import gov.nasa.pds.api.registry.model.exceptions.AcceptFormatNotSupportedException; -import gov.nasa.pds.api.registry.model.exceptions.SortSearchAfterMismatchException; -import gov.nasa.pds.api.registry.model.exceptions.NotFoundException; -import gov.nasa.pds.api.registry.model.exceptions.RegistryApiException; -import gov.nasa.pds.api.registry.model.exceptions.UnhandledException; -import gov.nasa.pds.api.registry.model.exceptions.UnparsableQParamException; - @ControllerAdvice @@ -49,6 +44,12 @@ protected ResponseEntity notFound(NotFoundException ex, WebRequest reque } + @ExceptionHandler(value = {BadRequestException.class}) + protected ResponseEntity badRequest(BadRequestException ex, WebRequest request) { + return genericExceptionHandler(ex, request, "", HttpStatus.BAD_REQUEST); + + } + @ExceptionHandler(value = {UnhandledException.class}) protected ResponseEntity unhandled(UnhandledException ex, WebRequest request) { return genericExceptionHandler(ex, request, "", HttpStatus.INTERNAL_SERVER_ERROR); diff --git a/service/src/main/java/gov/nasa/pds/api/registry/model/exceptions/BadRequestException.java b/service/src/main/java/gov/nasa/pds/api/registry/model/exceptions/BadRequestException.java new file mode 100644 index 00000000..55345724 --- /dev/null +++ b/service/src/main/java/gov/nasa/pds/api/registry/model/exceptions/BadRequestException.java @@ -0,0 +1,17 @@ +package gov.nasa.pds.api.registry.model.exceptions; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.Serial; + +public class BadRequestException extends RegistryApiException { + private static final Logger log = LoggerFactory.getLogger(BadRequestException.class); + @Serial + private static final long serialVersionUID = 2026697251322082840L; + + public BadRequestException(String msg) { + super("BadRequestException: " + msg); + } + +} diff --git a/service/src/main/java/gov/nasa/pds/api/registry/model/exceptions/MiscellaneousBadRequestException.java b/service/src/main/java/gov/nasa/pds/api/registry/model/exceptions/MiscellaneousBadRequestException.java deleted file mode 100644 index b5904293..00000000 --- a/service/src/main/java/gov/nasa/pds/api/registry/model/exceptions/MiscellaneousBadRequestException.java +++ /dev/null @@ -1,20 +0,0 @@ -package gov.nasa.pds.api.registry.model.exceptions; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.Serial; - -/** - * Use as a catch-all for one-off errors where the request is bad and specific handling is not required - */ -public class MiscellaneousBadRequestException extends RegistryApiException { - private static final Logger log = LoggerFactory.getLogger(MiscellaneousBadRequestException.class); - @Serial - private static final long serialVersionUID = 2026697251322082840L; - - public MiscellaneousBadRequestException(String msg) { - super("MiscellaneousBadRequestException: " + msg); - } - -}