summaryrefslogtreecommitdiffstats
path: root/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/AppExceptionHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/AppExceptionHandler.java')
-rw-r--r--mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/AppExceptionHandler.java49
1 files changed, 46 insertions, 3 deletions
diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/AppExceptionHandler.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/AppExceptionHandler.java
index 1a2f5f9..b8aeca6 100644
--- a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/AppExceptionHandler.java
+++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/AppExceptionHandler.java
@@ -20,6 +20,9 @@
package org.onap.dcaegen2.platform.mod.web.controller;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.google.gson.Gson;
+import lombok.extern.slf4j.Slf4j;
import org.onap.dcaegen2.platform.mod.model.exceptions.MissingRequestBodyException;
import org.onap.dcaegen2.platform.mod.model.exceptions.OperationNotAllowedException;
import org.onap.dcaegen2.platform.mod.model.exceptions.ResourceConflictException;
@@ -27,12 +30,10 @@ import org.onap.dcaegen2.platform.mod.model.exceptions.basemicroservice.BaseMicr
import org.onap.dcaegen2.platform.mod.model.exceptions.common.UserNotPassedException;
import org.onap.dcaegen2.platform.mod.model.exceptions.deploymentartifact.DeploymentArtifactNotFound;
import org.onap.dcaegen2.platform.mod.model.exceptions.msinstance.MsInstanceNotFoundException;
+import org.onap.dcaegen2.platform.mod.model.exceptions.policymodel.PolicyModelNotFoundException;
import org.onap.dcaegen2.platform.mod.model.exceptions.specification.SpecificationInvalid;
import org.onap.dcaegen2.platform.mod.model.restapi.ErrorResponse;
import org.onap.dcaegen2.platform.mod.model.restapi.GenericErrorResponse;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.google.gson.Gson;
-import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.FieldError;
@@ -54,6 +55,9 @@ import java.util.Map;
@Slf4j
public class AppExceptionHandler {
+ /**
+ * Exception Handler for Invalid Component Spec
+ */
@ExceptionHandler(value = {WebClientResponseException.class})
public ResponseEntity<ErrorResponse> handleCompSpecInvalidException
(WebClientResponseException ex, WebRequest request) {
@@ -61,6 +65,9 @@ public class AppExceptionHandler {
(new ErrorResponse(ex.getResponseBodyAsString()), HttpStatus.INTERNAL_SERVER_ERROR);
}
+ /**
+ * Exception Handler for Json Parsing
+ */
@ExceptionHandler(value = {JsonParseException.class})
public ResponseEntity<GenericErrorResponse> handleJsonParsedException
(JsonParseException ex, WebRequest request) {
@@ -72,6 +79,9 @@ public class AppExceptionHandler {
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}
+ /**
+ * Exception Handler for Invalid Specification
+ */
@ExceptionHandler
public ResponseEntity<GenericErrorResponse> specificationInvalid(SpecificationInvalid ex) {
Map<String, Object> errorResponse = new Gson().fromJson(ex.getMessage(), Map.class);
@@ -82,6 +92,9 @@ public class AppExceptionHandler {
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}
+ /**
+ * Exception Handler for Missing requested Body
+ */
@ExceptionHandler
public ResponseEntity<GenericErrorResponse> missingRequestBodyException(MissingRequestBodyException ex){
GenericErrorResponse response = new GenericErrorResponse();
@@ -91,17 +104,35 @@ public class AppExceptionHandler {
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}
+ /**
+ * Exception Handler for missing User
+ */
@ExceptionHandler
public ResponseEntity<ErrorResponse> resolveUserNotPassedException(UserNotPassedException ex){
return new ResponseEntity<>(new ErrorResponse(ex.getMessage()), HttpStatus.BAD_REQUEST);
}
+ /**
+ * Exception Handler for MsInstance Not Found
+ */
@ExceptionHandler
public ResponseEntity<ErrorResponse> resolveMsInstanceNotFoundException(MsInstanceNotFoundException ex) {
log.error(ex.getMessage());
return new ResponseEntity<>(new ErrorResponse(ex.getMessage()), HttpStatus.BAD_REQUEST);
}
+ /**
+ * Exception Handler for Policy Model Not Found
+ */
+ @ExceptionHandler
+ public ResponseEntity<ErrorResponse> resolvePolicyModelNotFoundException(PolicyModelNotFoundException ex) {
+ log.error(ex.getMessage());
+ return new ResponseEntity<>(new ErrorResponse(ex.getMessage()), HttpStatus.BAD_REQUEST);
+ }
+
+ /**
+ * Exception Handler for Policy Model Not Found
+ */
@ExceptionHandler
public ResponseEntity<ErrorResponse> resolveDeploymentArtifactNotFound(DeploymentArtifactNotFound ex) {
log.error(ex.getMessage());
@@ -109,6 +140,9 @@ public class AppExceptionHandler {
HttpStatus.BAD_REQUEST);
}
+ /**
+ * Exception Handler for Operation Not Allowed
+ */
@ExceptionHandler
public ResponseEntity<ErrorResponse> resolveOperationNotAllowed(OperationNotAllowedException ex) {
log.error(ex.getMessage());
@@ -116,17 +150,26 @@ public class AppExceptionHandler {
HttpStatus.CONFLICT);
}
+ /**
+ * Exception Handler for Resource Conflict
+ */
@ExceptionHandler
public ResponseEntity<ErrorResponse> resolveResourceConflict(ResourceConflictException ex) {
return new ResponseEntity<>(new ErrorResponse(ex.getMessage()), HttpStatus.CONFLICT);
}
+ /**
+ * Exception Handler for Resource Not Found
+ */
@ExceptionHandler(value = {BaseMicroserviceNotFoundException.class})
public ResponseEntity<ErrorResponse> resolveResourceNotFoundExcetions(RuntimeException ex) {
log.error(ex.getMessage(), ex);
return new ResponseEntity<>(new ErrorResponse(ex.getMessage()), HttpStatus.CONFLICT);
}
+ /**
+ * Exception Handler for Bean Validation
+ */
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<GenericErrorResponse> resolveBeanValidationException(MethodArgumentNotValidException ex){
log.error(ex.getMessage());