|
2 | 2 |
|
3 | 3 | import org.springframework.http.HttpStatus; |
4 | 4 | import org.springframework.http.ResponseEntity; |
5 | | -import org.springframework.web.bind.annotation.ControllerAdvice; |
6 | 5 | import org.springframework.web.bind.annotation.ExceptionHandler; |
7 | 6 | import org.springframework.web.bind.annotation.RestControllerAdvice; |
8 | | -import org.springframework.web.servlet.NoHandlerFoundException; |
9 | 7 |
|
10 | | -import javax.persistence.EntityNotFoundException; |
| 8 | +import java.util.ArrayList; |
| 9 | +import java.util.List; |
11 | 10 |
|
12 | 11 | /** |
13 | 12 | * @author : Burak KUTBAY |
|
17 | 16 | public class CustomExceptionHandler { |
18 | 17 |
|
19 | 18 | @ExceptionHandler(CustomerNotFoundException.class) |
20 | | - public ResponseEntity<String> customerNotFoundException(CustomerNotFoundException customerNotFoundException) { |
21 | | - return new ResponseEntity<String>(customerNotFoundException.getMessage(), HttpStatus.BAD_REQUEST); |
| 19 | + public ResponseEntity<?> customerNotFoundException(CustomerNotFoundException customerNotFoundException) { |
| 20 | + List<String> detail = new ArrayList<>(); |
| 21 | + detail.add(customerNotFoundException.getMessage()); |
| 22 | + ErrorResponse errorResponse = new ErrorResponse("Customer Not Found", detail); |
| 23 | + return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); |
22 | 24 | } |
23 | 25 |
|
24 | | - @ExceptionHandler({NoHandlerFoundException.class, EntityNotFoundException.class,CustomerNotNullException.class}) |
25 | | - public ResponseEntity<String> customerNotNull(CustomerNotNullException customerNotNullException) { |
26 | | - return new ResponseEntity<String>(customerNotNullException.getMessage(), HttpStatus.BAD_REQUEST); |
| 26 | + @ExceptionHandler(CustomerNotNullException.class) |
| 27 | + public ResponseEntity<?> customerNotNull(CustomerNotNullException customerNotNullException) { |
| 28 | + List<String> detail = new ArrayList<>(); |
| 29 | + detail.add(customerNotNullException.getMessage()); |
| 30 | + ErrorResponse errorResponse = new ErrorResponse("Customer Not Null", detail); |
| 31 | + return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); |
27 | 32 | } |
28 | 33 |
|
29 | 34 |
|
|
0 commit comments