1 package org.onap.sdc.workflow.api.exceptionshandlers;
3 import static org.springframework.http.HttpStatus.FORBIDDEN;
4 import static org.springframework.http.HttpStatus.NOT_FOUND;
5 import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
7 import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
8 import org.onap.sdc.workflow.services.exceptions.InvalidArtifactException;
9 import org.onap.sdc.workflow.services.exceptions.UniqueValueViolationException;
10 import org.onap.sdc.workflow.services.exceptions.CreateVersionException;
11 import org.onap.sdc.workflow.services.exceptions.VersionModificationException;
12 import org.springframework.http.ResponseEntity;
13 import org.springframework.web.bind.annotation.ControllerAdvice;
14 import org.springframework.web.bind.annotation.ExceptionHandler;
15 import org.springframework.web.bind.annotation.RestController;
16 import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
20 public class CustomizedResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
22 @ExceptionHandler(UniqueValueViolationException.class)
23 public final ResponseEntity<String> handleUniqueValueViolationException(
24 UniqueValueViolationException exception) {
25 return new ResponseEntity<>(exception.getMessage(), UNPROCESSABLE_ENTITY);
28 @ExceptionHandler(EntityNotFoundException.class)
29 public final ResponseEntity<String> handleWorkflowNotFoundException(
30 Exception exception) {
31 return new ResponseEntity<>(exception.getMessage(), NOT_FOUND);
34 @ExceptionHandler({InvalidArtifactException.class, VersionModificationException.class})
35 public final ResponseEntity<String> handleInvalidArtifactException(
36 Exception exception) {
37 return new ResponseEntity<>(exception.getMessage(), UNPROCESSABLE_ENTITY);
41 @ExceptionHandler(CreateVersionException.class)
42 public final ResponseEntity<String> handleVersioningErrorException(
43 CreateVersionException exception) {
44 return new ResponseEntity<>(exception.getMessage(), FORBIDDEN);