Skip to content

Commit

Permalink
Added GlobalExceptionHandler + ErrorResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
kiblykat committed Mar 24, 2024
1 parent 421a625 commit 7db523c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
15 changes: 15 additions & 0 deletions src/main/java/sg/com/smartinventory/exceptions/ErrorResponse.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,15 +22,6 @@ public ResponseEntity<ErrorResponse> handleResourceNotFoundException(CustomerNot
return new ResponseEntity<>(errorResponse, HttpStatus.NOT_FOUND);
}

// @ExceptionHandler(ProductNotFoundException.class)
// public ResponseEntity<ErrorResponse>
// handleProductNotFoundException(CustomerNotFoundException ex){
// ErrorResponse errorResponse = new ErrorResponse(ex.getMessage(),
// LocalDateTime.now());
//
// return new ResponseEntity<>(errorResponse, HttpStatus.NOT_FOUND);
// }

@ExceptionHandler(EmptyResultDataAccessException.class)
public ResponseEntity<ErrorResponse> handleEmptyResultDataAccessException(EmptyResultDataAccessException ex) {
ErrorResponse errorResponse = new ErrorResponse("Entry does not exist. ", LocalDateTime.now());
Expand Down

0 comments on commit 7db523c

Please sign in to comment.