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.VersionCreationException;
11 import org.onap.sdc.workflow.services.exceptions.VersionModificationException;
12 import org.onap.sdc.workflow.services.exceptions.VersionStateModificationException;
13 import org.springframework.http.ResponseEntity;
14 import org.springframework.web.bind.annotation.ControllerAdvice;
15 import org.springframework.web.bind.annotation.ExceptionHandler;
16 import org.springframework.web.bind.annotation.RestController;
17 import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
21 public class CustomizedResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
23 @ExceptionHandler(UniqueValueViolationException.class)
24 public final ResponseEntity<String> handleUniqueValueViolationException(
25 UniqueValueViolationException exception) {
26 return new ResponseEntity<>(exception.getMessage(), UNPROCESSABLE_ENTITY);
29 @ExceptionHandler(EntityNotFoundException.class)
30 public final ResponseEntity<String> handleWorkflowNotFoundException(
31 Exception exception) {
32 return new ResponseEntity<>(exception.getMessage(), NOT_FOUND);
35 @ExceptionHandler({InvalidArtifactException.class, VersionModificationException.class,
36 VersionStateModificationException.class})
37 public final ResponseEntity<String> handleInvalidArtifactException(
38 Exception exception) {
39 return new ResponseEntity<>(exception.getMessage(), UNPROCESSABLE_ENTITY);
43 @ExceptionHandler(VersionCreationException.class)
44 public final ResponseEntity<String> handleVersioningErrorException(
45 VersionCreationException exception) {
46 return new ResponseEntity<>(exception.getMessage(), FORBIDDEN);