Class CustomExceptionHandler
java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
com.example.vehicletaxsystem.config.CustomExceptionHandler
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.context.MessageSourceAware
@ControllerAdvice
public class CustomExceptionHandler
extends org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
Custom exception handler to handle exceptions thrown by application.
-
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 TypeMethodDescriptionprotected org.springframework.http.ResponseEntity<Object>handleInvalidRequest(Exception exception) Custom exception handling method - handles all invalid entity exceptions and the more generic InvalidRequestException.Methods 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
-
CustomExceptionHandler
public CustomExceptionHandler()
-
-
Method Details
-
handleInvalidRequest
@ResponseStatus(BAD_REQUEST) @ExceptionHandler({InvalidAddressException.class,InvalidDriverException.class,InvalidTaxBandException.class,InvalidTaxPaymentException.class,InvalidVehicleException.class,InvalidRequestException.class}) protected org.springframework.http.ResponseEntity<Object> handleInvalidRequest(Exception exception) Custom exception handling method - handles all invalid entity exceptions and the more generic InvalidRequestException.- Parameters:
exception- exception class - identifies the type of exception thrown.- Returns:
- HTTP Response entity with error message and bad request header.
-