978be192ca5be0bf71d88f23aa5fb2441f31663d
[sdc/sdc-workflow-designer.git] /
1 package org.onap.sdc.workflow.api.exceptionshandlers;
2
3 import static org.springframework.http.HttpStatus.NOT_FOUND;
4 import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
5
6 import org.onap.sdc.workflow.services.exceptions.UniqueValueViolationException;
7 import org.onap.sdc.workflow.services.exceptions.VersionNotFoundException;
8 import org.onap.sdc.workflow.services.exceptions.WorkflowNotFoundException;
9 import org.springframework.http.ResponseEntity;
10 import org.springframework.web.bind.annotation.ControllerAdvice;
11 import org.springframework.web.bind.annotation.ExceptionHandler;
12 import org.springframework.web.bind.annotation.RestController;
13 import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
14
15 @ControllerAdvice
16 @RestController
17 public class CustomizedResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
18
19     @ExceptionHandler(UniqueValueViolationException.class)
20     public final ResponseEntity<String> handleUniqueValueViolationException(
21             UniqueValueViolationException exception) {
22         return new ResponseEntity<>(exception.getMessage(), UNPROCESSABLE_ENTITY);
23     }
24
25     @ExceptionHandler({WorkflowNotFoundException.class, VersionNotFoundException.class})
26     public final ResponseEntity<String> handleWorkflowNotFoundException(
27             Exception exception) {
28         return new ResponseEntity<>(exception.getMessage(), NOT_FOUND);
29     }
30 }