summaryrefslogtreecommitdiffstats
path: root/cps-rest/src/main
diff options
context:
space:
mode:
authorRuslan Kashapov <ruslan.kashapov@pantheon.tech>2021-05-19 10:43:39 +0300
committerRuslan Kashapov <ruslan.kashapov@pantheon.tech>2021-05-20 12:42:40 +0300
commitb42a3ced30877da19ce205c66539e4a286ccd458 (patch)
treef0d49cd725ee067ec0b07b7046c6709aeddd6428 /cps-rest/src/main
parentbd35b4d03a474ce425040cc4656c7b94a87ef399 (diff)
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 <ruslan.kashapov@pantheon.tech>
Diffstat (limited to 'cps-rest/src/main')
-rwxr-xr-xcps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java8
1 files changed, 6 insertions, 2 deletions
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<Object> handleNotFoundExceptions(final CpsException exception) {
- return buildErrorResponse(HttpStatus.NOT_FOUND, exception);
+ public static ResponseEntity<Object> 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})