Class GlobalExceptionHandler
java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
org.training.user.service.exception.GlobalExceptionHandler
@RestControllerAdvice
public class GlobalExceptionHandler
extends org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
-
Field Summary
Fields inherited from class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
logger, PAGE_NOT_FOUND_LOG_CATEGORY, pageNotFoundLogger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<Object>handleGlobalException(GlobalException globalException) Handles global exceptions.protected org.springframework.http.ResponseEntity<Object>handleMethodArgumentNotValid(org.springframework.web.bind.MethodArgumentNotValidException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request) Handles the case when a method argument is not valid.Methods inherited from class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
handleAsyncRequestTimeoutException, handleBindException, handleConversionNotSupported, handleException, handleExceptionInternal, handleHttpMediaTypeNotAcceptable, handleHttpMediaTypeNotSupported, handleHttpMessageNotReadable, handleHttpMessageNotWritable, handleHttpRequestMethodNotSupported, handleMissingPathVariable, handleMissingServletRequestParameter, handleMissingServletRequestPart, handleNoHandlerFoundException, handleServletRequestBindingException, handleTypeMismatch
-
Constructor Details
-
GlobalExceptionHandler
public GlobalExceptionHandler()
-
-
Method Details
-
handleMethodArgumentNotValid
protected org.springframework.http.ResponseEntity<Object> handleMethodArgumentNotValid(org.springframework.web.bind.MethodArgumentNotValidException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request) Handles the case when a method argument is not valid.- Overrides:
handleMethodArgumentNotValidin classorg.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler- Parameters:
ex- The MethodArgumentNotValidException that was thrown.headers- The HttpHeaders object for the response.status- The HttpStatus for the response.request- The WebRequest object for the response.- Returns:
- A ResponseEntity containing an ErrorResponse object with the error code and localized message, and the HTTP status code.
-
handleGlobalException
@ExceptionHandler(GlobalException.class) public org.springframework.http.ResponseEntity<Object> handleGlobalException(GlobalException globalException) Handles global exceptions.- Parameters:
globalException- The global exception to handle.- Returns:
- The response entity with the error response.
-