From 87a6cac6b316dd1511f2b46ba5c3d8ef4fa45239 Mon Sep 17 00:00:00 2001 From: murtuza-ranapur Date: Mon, 28 Dec 2020 23:13:28 +0530 Subject: [PATCH] Adds logs --- .../exception/exception/GlobalExceptionHandler.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spring-boot/exception-handling/src/main/java/io/reflectoring/exception/exception/GlobalExceptionHandler.java b/spring-boot/exception-handling/src/main/java/io/reflectoring/exception/exception/GlobalExceptionHandler.java index 283c253..fb3a5aa 100644 --- a/spring-boot/exception-handling/src/main/java/io/reflectoring/exception/exception/GlobalExceptionHandler.java +++ b/spring-boot/exception-handling/src/main/java/io/reflectoring/exception/exception/GlobalExceptionHandler.java @@ -41,12 +41,14 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { @ExceptionHandler(NoSuchElementFoundException.class) @ResponseStatus(HttpStatus.NOT_FOUND) public ResponseEntity handleNoSuchElementFoundException(NoSuchElementFoundException itemNotFoundException, WebRequest request) { + log.error("Failed to find the requested element", itemNotFoundException); return buildErrorResponse(itemNotFoundException, HttpStatus.NOT_FOUND, request); } - @ExceptionHandler(RuntimeException.class) + @ExceptionHandler(Exception.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) - public ResponseEntity handleAllUncaughtException(RuntimeException exception, WebRequest request) { + public ResponseEntity handleAllUncaughtException(Exception exception, WebRequest request) { + log.error("Unknown error occurred", exception); return buildErrorResponse(exception, "Unknown error occurred", HttpStatus.INTERNAL_SERVER_ERROR, request); }