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 generalException
sorg.springframework.http.ResponseEntity<Object>
handleIllegalArgumentException
(IllegalArgumentException exception, jakarta.servlet.http.HttpServletRequest request) Handle allIllegalArgumentException
sorg.springframework.http.ResponseEntity<Object>
handleNoSuchElementException
(NoSuchElementException exception, jakarta.servlet.http.HttpServletRequest request) Handle allNoSuchElementException
sorg.springframework.http.ResponseEntity<Object>
handleUnsupportedOperationException
(UnsupportedOperationException exception, jakarta.servlet.http.HttpServletRequest request) Handle allUnsupportedOperationException
sMethods inherited from class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
createProblemDetail, createResponseEntity, getMessageSource, handleAsyncRequestTimeoutException, handleBindException, handleConversionNotSupported, handleErrorResponseException, handleException, handleExceptionInternal, handleHandlerMethodValidationException, handleHttpMediaTypeNotAcceptable, handleHttpMediaTypeNotSupported, handleHttpMessageNotReadable, handleHttpMessageNotWritable, handleHttpRequestMethodNotSupported, handleMaxUploadSizeExceededException, handleMethodArgumentNotValid, handleMethodValidationException, handleMissingPathVariable, handleMissingServletRequestParameter, handleMissingServletRequestPart, handleNoHandlerFoundException, handleNoResourceFoundException, 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 generalException
s- Parameters:
exception
- the exceptionrequest
- the current request- Returns:
- a
ResponseEntity
instance
-
handleIllegalArgumentException
@ExceptionHandler(java.lang.IllegalArgumentException.class) public org.springframework.http.ResponseEntity<Object> handleIllegalArgumentException(IllegalArgumentException exception, jakarta.servlet.http.HttpServletRequest request) Handle allIllegalArgumentException
s- Parameters:
exception
- the exceptionrequest
- the current request- Returns:
- a
ResponseEntity
instance
-
handleNoSuchElementException
@ExceptionHandler(java.util.NoSuchElementException.class) public org.springframework.http.ResponseEntity<Object> handleNoSuchElementException(NoSuchElementException exception, jakarta.servlet.http.HttpServletRequest request) Handle allNoSuchElementException
s- Parameters:
exception
- the exceptionrequest
- the current request- Returns:
- a
ResponseEntity
instance
-
handleUnsupportedOperationException
@ExceptionHandler(java.lang.UnsupportedOperationException.class) public org.springframework.http.ResponseEntity<Object> handleUnsupportedOperationException(UnsupportedOperationException exception, jakarta.servlet.http.HttpServletRequest request) Handle allUnsupportedOperationException
s- Parameters:
exception
- the exceptionrequest
- the current request- Returns:
- a
ResponseEntity
instance
-