From 7db523cbc3836a849dd20d974a67b387becd57d7 Mon Sep 17 00:00:00 2001 From: kiblykat Date: Sun, 24 Mar 2024 17:04:27 +0800 Subject: [PATCH] Added GlobalExceptionHandler + ErrorResponse --- .../smartinventory/exceptions/ErrorResponse.java | 15 +++++++++++++++ ...ndler.java.dev => GlobalExceptionHandler.java} | 11 ----------- 2 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 src/main/java/sg/com/smartinventory/exceptions/ErrorResponse.java rename src/main/java/sg/com/smartinventory/exceptions/{GlobalExceptionHandler.java.dev => GlobalExceptionHandler.java} (86%) diff --git a/src/main/java/sg/com/smartinventory/exceptions/ErrorResponse.java b/src/main/java/sg/com/smartinventory/exceptions/ErrorResponse.java new file mode 100644 index 0000000..a2248e2 --- /dev/null +++ b/src/main/java/sg/com/smartinventory/exceptions/ErrorResponse.java @@ -0,0 +1,15 @@ +package sg.com.smartinventory.exceptions; + +import java.time.LocalDateTime; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +public class ErrorResponse { + private String message; + private LocalDateTime timeStamp; +} diff --git a/src/main/java/sg/com/smartinventory/exceptions/GlobalExceptionHandler.java.dev b/src/main/java/sg/com/smartinventory/exceptions/GlobalExceptionHandler.java similarity index 86% rename from src/main/java/sg/com/smartinventory/exceptions/GlobalExceptionHandler.java.dev rename to src/main/java/sg/com/smartinventory/exceptions/GlobalExceptionHandler.java index 50d9e6c..39c470d 100644 --- a/src/main/java/sg/com/smartinventory/exceptions/GlobalExceptionHandler.java.dev +++ b/src/main/java/sg/com/smartinventory/exceptions/GlobalExceptionHandler.java @@ -3,8 +3,6 @@ import java.time.LocalDateTime; import java.util.List; -import sg.com.smartinventory.entities.ErrorResponse; - import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -24,15 +22,6 @@ public ResponseEntity handleResourceNotFoundException(CustomerNot return new ResponseEntity<>(errorResponse, HttpStatus.NOT_FOUND); } - // @ExceptionHandler(ProductNotFoundException.class) - // public ResponseEntity - // handleProductNotFoundException(CustomerNotFoundException ex){ - // ErrorResponse errorResponse = new ErrorResponse(ex.getMessage(), - // LocalDateTime.now()); - // - // return new ResponseEntity<>(errorResponse, HttpStatus.NOT_FOUND); - // } - @ExceptionHandler(EmptyResultDataAccessException.class) public ResponseEntity handleEmptyResultDataAccessException(EmptyResultDataAccessException ex) { ErrorResponse errorResponse = new ErrorResponse("Entry does not exist. ", LocalDateTime.now());