Class ControllerExceptionHandler
java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
io.github.astrapi69.spring.exceptionhandling.ControllerExceptionHandler
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.context.MessageSourceAware
@ControllerAdvice(annotations=org.springframework.web.bind.annotation.RestController.class)
public class ControllerExceptionHandler
extends org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
The class
ControllerExceptionHandler handles specified exceptions for rest controllers-
Field Summary
Fields inherited from class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
logger, PAGE_NOT_FOUND_LOG_CATEGORY, pageNotFoundLogger -
Constructor Summary
ConstructorsConstructorDescriptionControllerExceptionHandler(org.springframework.context.MessageSource messageSource) -
Method Summary
Modifier and TypeMethodDescriptionprotected org.springframework.http.ResponseEntity<Object>handleBindException(org.springframework.validation.BindException exception, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request) org.springframework.http.ResponseEntity<Object>handleException(Exception exception, jakarta.servlet.http.HttpServletRequest request) Handle all generalExceptionsorg.springframework.http.ResponseEntity<Object>handleIllegalArgumentException(IllegalArgumentException exception, jakarta.servlet.http.HttpServletRequest request) Handle allIllegalArgumentExceptionsorg.springframework.http.ResponseEntity<Object>handleNoSuchElementException(NoSuchElementException exception, jakarta.servlet.http.HttpServletRequest request) Handle allNoSuchElementExceptionsorg.springframework.http.ResponseEntity<Object>handleUnsupportedOperationException(UnsupportedOperationException exception, jakarta.servlet.http.HttpServletRequest request) Handle allUnsupportedOperationExceptionsMethods inherited from class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
createProblemDetail, createResponseEntity, getMessageSource, handleAsyncRequestTimeoutException, handleBindException, handleConversionNotSupported, handleErrorResponseException, handleException, handleExceptionInternal, handleHttpMediaTypeNotAcceptable, handleHttpMediaTypeNotSupported, handleHttpMessageNotReadable, handleHttpMessageNotWritable, handleHttpRequestMethodNotSupported, handleMethodArgumentNotValid, handleMissingPathVariable, handleMissingServletRequestParameter, handleMissingServletRequestPart, handleNoHandlerFoundException, handleServletRequestBindingException, handleTypeMismatch, setMessageSource
-
Constructor Details
-
ControllerExceptionHandler
public ControllerExceptionHandler(org.springframework.context.MessageSource messageSource)
-
-
Method Details
-
handleBindException
protected org.springframework.http.ResponseEntity<Object> handleBindException(org.springframework.validation.BindException exception, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request) -
handleException
@ExceptionHandler(java.lang.Exception.class) public org.springframework.http.ResponseEntity<Object> handleException(Exception exception, jakarta.servlet.http.HttpServletRequest request) Handle all generalExceptions- Parameters:
exception- the exceptionrequest- the current request- Returns:
- a
ResponseEntityinstance
-
handleIllegalArgumentException
@ExceptionHandler(java.lang.IllegalArgumentException.class) public org.springframework.http.ResponseEntity<Object> handleIllegalArgumentException(IllegalArgumentException exception, jakarta.servlet.http.HttpServletRequest request) Handle allIllegalArgumentExceptions- Parameters:
exception- the exceptionrequest- the current request- Returns:
- a
ResponseEntityinstance
-
handleNoSuchElementException
@ExceptionHandler(java.util.NoSuchElementException.class) public org.springframework.http.ResponseEntity<Object> handleNoSuchElementException(NoSuchElementException exception, jakarta.servlet.http.HttpServletRequest request) Handle allNoSuchElementExceptions- Parameters:
exception- the exceptionrequest- the current request- Returns:
- a
ResponseEntityinstance
-
handleUnsupportedOperationException
@ExceptionHandler(java.lang.UnsupportedOperationException.class) public org.springframework.http.ResponseEntity<Object> handleUnsupportedOperationException(UnsupportedOperationException exception, jakarta.servlet.http.HttpServletRequest request) Handle allUnsupportedOperationExceptions- Parameters:
exception- the exceptionrequest- the current request- Returns:
- a
ResponseEntityinstance
-