c29d2ab1fe04fcdecd6a52c9e10b939c91afbaae
[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.WorkflowNotFoundException;
8 import org.springframework.http.ResponseEntity;
9 import org.springframework.web.bind.annotation.ControllerAdvice;
10 import org.springframework.web.bind.annotation.ExceptionHandler;
11 import org.springframework.web.bind.annotation.RestController;
12 import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
13
14 @ControllerAdvice
15 @RestController
16 public class CustomizedResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
17
18     @ExceptionHandler(UniqueValueViolationException.class)
19     public final ResponseEntity<String> handleUniqueValueViolationException(
20             UniqueValueViolationException exception) {
21         return new ResponseEntity<>(exception.getMessage(), UNPROCESSABLE_ENTITY);
22     }
23
24     @ExceptionHandler(WorkflowNotFoundException.class)
25     public final ResponseEntity<String> handleWorkflowNotFoundException(
26             WorkflowNotFoundException exception) {
27         return new ResponseEntity<>(exception.getMessage(), NOT_FOUND);
28     }
29 }