Class GlobalExceptionHandler
java.lang.Object
tech.lastbox.lastshield.security.core.GlobalExceptionHandler
Global exception handler that handles
RuntimeException exceptions across the entire application.
This class is annotated with ControllerAdvice, allowing it to handle exceptions globally and return
a standardized error response to the client. When a RuntimeException is thrown, the handler constructs an
ErrorResponse with the exception message, the HTTP status code, and a timestamp, and then returns it
as part of a ResponseEntity.
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor for the GlobalExceptionHandler class. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<?> HandlesRuntimeExceptionby creating anErrorResponsewith the exception message and aHttpStatus.BAD_REQUESTstatus code, then returns it as part of aResponseEntitywith aHttpStatus.NOT_FOUNDresponse status.
-
Constructor Details
-
GlobalExceptionHandler
public GlobalExceptionHandler()Default constructor for the GlobalExceptionHandler class. This constructor is used to instantiate the GlobalExceptionHandler class.
-
-
Method Details
-
handleResourceNotFoundException
@ExceptionHandler(java.lang.RuntimeException.class) public org.springframework.http.ResponseEntity<?> handleResourceNotFoundException(RuntimeException ex) HandlesRuntimeExceptionby creating anErrorResponsewith the exception message and aHttpStatus.BAD_REQUESTstatus code, then returns it as part of aResponseEntitywith aHttpStatus.NOT_FOUNDresponse status.- Parameters:
ex- theRuntimeExceptionthat was thrown.- Returns:
- a
ResponseEntitycontaining theErrorResponsewith aHttpStatus.NOT_FOUNDstatus.
-