Class GlobalExceptionHandler
java.lang.Object
com.bayudwiyansatria.spring.exception.GlobalExceptionHandler
GlobalExceptionHandler
This class provides global exception handling for the application. It handles specific exceptions and returns appropriate HTTP responses.
It is annotated with @ControllerAdvice
to indicate that it provides centralized
exception handling across all @RequestMapping
methods.
- Since:
- 0.0.1
- Version:
- 0.0.1
- Author:
- Bayu Dwiyan Satria
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<String>
HandlesMongoConfigurationException
and returns a 500 Internal Server Error status.HandlesRuntimeException
and returns a 404 Not Found status.
-
Constructor Details
-
GlobalExceptionHandler
public GlobalExceptionHandler()
-
-
Method Details
-
handleNotFoundException
@ExceptionHandler(java.lang.RuntimeException.class) @ResponseStatus(NOT_FOUND) public String handleNotFoundException(RuntimeException e) HandlesRuntimeException
and returns a 404 Not Found status.- Parameters:
e
- the RuntimeException to handle- Returns:
- the error message
- Since:
- 0.0.1
-
handleMongoConnectionException
@ExceptionHandler(MongoConfigurationException.class) public org.springframework.http.ResponseEntity<String> handleMongoConnectionException(MongoConfigurationException ex) HandlesMongoConfigurationException
and returns a 500 Internal Server Error status.- Parameters:
ex
- the MongoConfigurationException to handle- Returns:
- a ResponseEntity with the error message and HTTP status
- Since:
- 0.0.1
-