Skip to content

Commit 87a6cac

Browse files
Adds logs
1 parent fef6c48 commit 87a6cac

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

spring-boot/exception-handling/src/main/java/io/reflectoring/exception/exception/GlobalExceptionHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotV
4141
@ExceptionHandler(NoSuchElementFoundException.class)
4242
@ResponseStatus(HttpStatus.NOT_FOUND)
4343
public ResponseEntity<Object> handleNoSuchElementFoundException(NoSuchElementFoundException itemNotFoundException, WebRequest request) {
44+
log.error("Failed to find the requested element", itemNotFoundException);
4445
return buildErrorResponse(itemNotFoundException, HttpStatus.NOT_FOUND, request);
4546
}
4647

47-
@ExceptionHandler(RuntimeException.class)
48+
@ExceptionHandler(Exception.class)
4849
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
49-
public ResponseEntity<Object> handleAllUncaughtException(RuntimeException exception, WebRequest request) {
50+
public ResponseEntity<Object> handleAllUncaughtException(Exception exception, WebRequest request) {
51+
log.error("Unknown error occurred", exception);
5052
return buildErrorResponse(exception, "Unknown error occurred", HttpStatus.INTERNAL_SERVER_ERROR, request);
5153
}
5254

0 commit comments

Comments
 (0)