Skip to content

Commit 117efa8

Browse files
committed
https://blog.burakkutbay.com
1 parent 0555df9 commit 117efa8

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/main/java/com/burakkutbay/springbootexceptionhandler/exception/CustomExceptionHandler.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
import org.springframework.http.HttpStatus;
44
import org.springframework.http.ResponseEntity;
5+
import org.springframework.web.bind.annotation.ControllerAdvice;
56
import org.springframework.web.bind.annotation.ExceptionHandler;
67
import org.springframework.web.bind.annotation.RestControllerAdvice;
8+
import org.springframework.web.servlet.NoHandlerFoundException;
9+
10+
import javax.persistence.EntityNotFoundException;
711

812
/**
913
* @author : Burak KUTBAY
@@ -17,9 +21,9 @@ public ResponseEntity<String> customerNotFoundException(CustomerNotFoundExceptio
1721
return new ResponseEntity<String>(customerNotFoundException.getMessage(), HttpStatus.BAD_REQUEST);
1822
}
1923

20-
@ExceptionHandler(CustomerNotNullException.class)
24+
@ExceptionHandler({NoHandlerFoundException.class, EntityNotFoundException.class,CustomerNotNullException.class})
2125
public ResponseEntity<String> customerNotNull(CustomerNotNullException customerNotNullException) {
22-
return new ResponseEntity<String>(customerNotNullException.getMessage(), HttpStatus.NO_CONTENT);
26+
return new ResponseEntity<String>(customerNotNullException.getMessage(), HttpStatus.BAD_REQUEST);
2327
}
2428

2529

src/main/java/com/burakkutbay/springbootexceptionhandler/exception/CustomerNotNullException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @author : Burak KUTBAY
55
* Date : 28.11.2021
66
*/
7-
public class CustomerNotNullException extends IllegalArgumentException {
7+
public class CustomerNotNullException extends RuntimeException {
88
public CustomerNotNullException(String message){
99
super(message);
1010
}

0 commit comments

Comments
 (0)