From b42a3ced30877da19ce205c66539e4a286ccd458 Mon Sep 17 00:00:00 2001 From: Ruslan Kashapov Date: Wed, 19 May 2021 10:43:39 +0300 Subject: Response code fix (Bad Request instead of Not Found) when modifying non-existent node. Issue-ID: CPS-422 Change-Id: I6652f8bcafb9938ce588be3d0a0d2bb1672723b0 Signed-off-by: Ruslan Kashapov --- .../org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'cps-rest/src/main/java/org/onap') diff --git a/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java b/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java index 2a89ef2230..c61400d0c5 100755 --- a/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java +++ b/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java @@ -20,6 +20,7 @@ package org.onap.cps.rest.exceptions; +import javax.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; import org.onap.cps.rest.controller.AdminRestController; import org.onap.cps.rest.controller.DataRestController; @@ -34,6 +35,7 @@ import org.onap.cps.spi.exceptions.DataNodeNotFoundException; import org.onap.cps.spi.exceptions.DataValidationException; import org.onap.cps.spi.exceptions.ModelValidationException; import org.onap.cps.spi.exceptions.NotFoundInDataspaceException; +import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -65,8 +67,10 @@ public class CpsRestExceptionHandler { } @ExceptionHandler({NotFoundInDataspaceException.class, DataNodeNotFoundException.class}) - public static ResponseEntity handleNotFoundExceptions(final CpsException exception) { - return buildErrorResponse(HttpStatus.NOT_FOUND, exception); + public static ResponseEntity handleNotFoundExceptions(final CpsException exception, + final HttpServletRequest request) { + return buildErrorResponse(HttpMethod.GET.matches(request.getMethod()) + ? HttpStatus.NOT_FOUND : HttpStatus.BAD_REQUEST, exception); } @ExceptionHandler({DataInUseException.class, AlreadyDefinedException.class}) -- cgit 1.2.3-korg