Class ControllerExceptionHandler
- java.lang.Object
-
- org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
-
- io.github.astrapi69.spring.exceptionhandling.ControllerExceptionHandler
-
@ControllerAdvice(annotations=org.springframework.web.bind.annotation.RestController.class) public class ControllerExceptionHandler extends org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
The classControllerExceptionHandler
handles specified exceptions for rest controllers
-
-
Constructor Summary
Constructors Constructor Description ControllerExceptionHandler(org.springframework.context.MessageSource messageSource)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.springframework.http.ResponseEntity<java.lang.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<java.lang.Object>
handleException(java.lang.Exception exception, javax.servlet.http.HttpServletRequest request)
Handle all generalException
sorg.springframework.http.ResponseEntity<java.lang.Object>
handleIllegalArgumentException(java.lang.IllegalArgumentException exception, javax.servlet.http.HttpServletRequest request)
Handle allIllegalArgumentException
sorg.springframework.http.ResponseEntity<java.lang.Object>
handleNoSuchElementException(java.util.NoSuchElementException exception, javax.servlet.http.HttpServletRequest request)
Handle allNoSuchElementException
sorg.springframework.http.ResponseEntity<java.lang.Object>
handleUnsupportedOperationException(java.lang.UnsupportedOperationException exception, javax.servlet.http.HttpServletRequest request)
Handle allUnsupportedOperationException
s-
Methods inherited from class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
handleAsyncRequestTimeoutException, handleConversionNotSupported, handleException, handleExceptionInternal, handleHttpMediaTypeNotAcceptable, handleHttpMediaTypeNotSupported, handleHttpMessageNotReadable, handleHttpMessageNotWritable, handleHttpRequestMethodNotSupported, handleMethodArgumentNotValid, handleMissingPathVariable, handleMissingServletRequestParameter, handleMissingServletRequestPart, handleNoHandlerFoundException, handleServletRequestBindingException, handleTypeMismatch
-
-
-
-
Method Detail
-
handleBindException
protected org.springframework.http.ResponseEntity<java.lang.Object> handleBindException(org.springframework.validation.BindException exception, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
- Overrides:
handleBindException
in classorg.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
-
handleException
@ExceptionHandler(java.lang.Exception.class) public org.springframework.http.ResponseEntity<java.lang.Object> handleException(java.lang.Exception exception, javax.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<java.lang.Object> handleIllegalArgumentException(java.lang.IllegalArgumentException exception, javax.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<java.lang.Object> handleNoSuchElementException(java.util.NoSuchElementException exception, javax.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<java.lang.Object> handleUnsupportedOperationException(java.lang.UnsupportedOperationException exception, javax.servlet.http.HttpServletRequest request)
Handle allUnsupportedOperationException
s- Parameters:
exception
- the exceptionrequest
- the current request- Returns:
- a
ResponseEntity
instance
-
-