Class ApplicationExceptionHandler
java.lang.Object
com.markvarga21.studentmanager.exception.handler.ApplicationExceptionHandler
A custom exception handler for dealing with
certain exceptions in the applications.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<Object>
handleConstraintViolationException
(jakarta.validation.ConstraintViolationException ex) Handles if the input fields are invalid.org.springframework.http.ResponseEntity<Object>
Handles if the date is invalid.org.springframework.http.ResponseEntity<Object>
Handles if the format of the student's birthdate is invalid or not yet supported.org.springframework.http.ResponseEntity<Object>
Handles the exception if the faces are not identical.org.springframework.http.ResponseEntity<Object>
handleInvalidGenderException
(org.springframework.http.converter.HttpMessageNotReadableException ex) Handles the exception if the inputted gender is invalid.org.springframework.http.ResponseEntity<Object>
Handles the exception if the passport is invalid.org.springframework.http.ResponseEntity<Object>
Handles the exception if the student's data are invalid.org.springframework.http.ResponseEntity<Object>
Handles if the user's credentials are invalid.org.springframework.http.ResponseEntity<Object>
Handles if the passport validation data cannot be found.org.springframework.http.ResponseEntity<Object>
Handles the exception if a report could not be found in the database.org.springframework.http.ResponseEntity<Object>
Handles the exception if a student cannot be found in the database.org.springframework.http.ResponseEntity<Object>
handleTokenExpiredException
(io.jsonwebtoken.ExpiredJwtException ex) Handles the exception if the JWT token has expired.org.springframework.http.ResponseEntity<Object>
Handles the exception if the faces are not identical.org.springframework.http.ResponseEntity<Object>
Handles if the user cannot be found in the database.org.springframework.http.ResponseEntity<Object>
handleValidationExceptions
(org.springframework.web.bind.MethodArgumentNotValidException ex) Handles if the user did not input the information correctly when using the application's endpoints.
-
Field Details
-
POINT_UNICODE
A bullet point character in unicode format.- See Also:
-
-
Constructor Details
-
ApplicationExceptionHandler
public ApplicationExceptionHandler()
-
-
Method Details
-
handleValidationExceptions
@ExceptionHandler(org.springframework.web.bind.MethodArgumentNotValidException.class) @ResponseStatus(BAD_REQUEST) public org.springframework.http.ResponseEntity<Object> handleValidationExceptions(org.springframework.web.bind.MethodArgumentNotValidException ex) Handles if the user did not input the information correctly when using the application's endpoints.- Parameters:
ex
- The exception is caused by the invalid field value.- Returns:
- A readable
ResponseEntity
containing useful information.
-
handleConstraintViolationException
@ExceptionHandler(jakarta.validation.ConstraintViolationException.class) @ResponseStatus(BAD_REQUEST) public org.springframework.http.ResponseEntity<Object> handleConstraintViolationException(jakarta.validation.ConstraintViolationException ex) Handles if the input fields are invalid.- Parameters:
ex
- The exception is caused by a constraint violation.- Returns:
- A readable
ResponseEntity
containing useful information.
-
handlePassportValidationDataNotFoundException
@ExceptionHandler(PassportValidationDataNotFoundException.class) @ResponseStatus(NOT_FOUND) public org.springframework.http.ResponseEntity<Object> handlePassportValidationDataNotFoundException(PassportValidationDataNotFoundException ex) Handles if the passport validation data cannot be found.- Parameters:
ex
- The exception caused by not founding the passport validation data.- Returns:
- A readable
ResponseEntity
containing useful information.
-
handleUserNotFoundException
@ExceptionHandler(UserNotFoundException.class) @ResponseStatus(NOT_FOUND) public org.springframework.http.ResponseEntity<Object> handleUserNotFoundException(UserNotFoundException ex) Handles if the user cannot be found in the database.- Parameters:
ex
- The exception is caused by not founding the user.- Returns:
- A readable
ResponseEntity
containing useful information.
-
handleInvalidUserCredentialsException
@ExceptionHandler(InvalidUserCredentialsException.class) @ResponseStatus(UNAUTHORIZED) public org.springframework.http.ResponseEntity<Object> handleInvalidUserCredentialsException(InvalidUserCredentialsException ex) Handles if the user's credentials are invalid.- Parameters:
ex
- The exception is caused by the invalid user credentials.- Returns:
- A readable
ResponseEntity
containing useful information.
-
handleStudentNotFoundException
@ExceptionHandler(StudentNotFoundException.class) @ResponseStatus(NOT_FOUND) public org.springframework.http.ResponseEntity<Object> handleStudentNotFoundException(StudentNotFoundException ex) Handles the exception if a student cannot be found in the database.- Parameters:
ex
- The exception is caused by not founding the student.- Returns:
- A readable
ResponseEntity
containing useful information.
-
handleReportNotFoundException
@ExceptionHandler(ReportNotFoundException.class) @ResponseStatus(NOT_FOUND) public org.springframework.http.ResponseEntity<Object> handleReportNotFoundException(StudentNotFoundException ex) Handles the exception if a report could not be found in the database.- Parameters:
ex
- The exception is caused by not founding the report.- Returns:
- A readable
ResponseEntity
containing useful information.
-
handleInvalidDateFormatException
@ExceptionHandler({java.time.format.DateTimeParseException.class,InvalidDateFormatException.class}) @ResponseStatus(NOT_ACCEPTABLE) public org.springframework.http.ResponseEntity<Object> handleInvalidDateFormatException(DateTimeParseException ex) Handles if the format of the student's birthdate is invalid or not yet supported.- Parameters:
ex
- The exception caused by incorrectly formatting the birthdate.- Returns:
- A readable
ResponseEntity
containing useful information.
-
handleInvalidDateException
@ExceptionHandler(InvalidDateException.class) @ResponseStatus(NOT_ACCEPTABLE) public org.springframework.http.ResponseEntity<Object> handleInvalidDateException(InvalidDateException ex) Handles if the date is invalid.- Parameters:
ex
- The exception is caused by the invalid date.- Returns:
- A readable
ResponseEntity
containing useful information about the error.
-
handleInvalidGenderException
@ExceptionHandler(org.springframework.http.converter.HttpMessageNotReadableException.class) @ResponseStatus(BAD_REQUEST) public org.springframework.http.ResponseEntity<Object> handleInvalidGenderException(org.springframework.http.converter.HttpMessageNotReadableException ex) Handles the exception if the inputted gender is invalid.- Parameters:
ex
- The exception is caused by the invalid gender.- Returns:
- A readable
ResponseEntity
containing useful information.
-
handleInvalidPassportException
@ExceptionHandler(InvalidPassportException.class) @ResponseStatus(NOT_ACCEPTABLE) public org.springframework.http.ResponseEntity<Object> handleInvalidPassportException(InvalidPassportException ex) Handles the exception if the passport is invalid.- Parameters:
ex
- The exception is caused by the invalid passport.- Returns:
- A readable
ResponseEntity
containing useful information.
-
handleInvalidFacesException
@ExceptionHandler(InvalidFacesException.class) @ResponseStatus(BAD_REQUEST) public org.springframework.http.ResponseEntity<Object> handleInvalidFacesException(InvalidFacesException ex) Handles the exception if the faces are not identical.- Parameters:
ex
- The exception is caused by the faces not being identical.- Returns:
- A readable
ResponseEntity
containing useful information.
-
handleInvalidStudentException
@ExceptionHandler(InvalidStudentException.class) @ResponseStatus(NOT_ACCEPTABLE) public org.springframework.http.ResponseEntity<Object> handleInvalidStudentException(InvalidStudentException ex) Handles the exception if the student's data are invalid.- Parameters:
ex
- The exception is caused by an invalid field.- Returns:
- A readable
ResponseEntity
containing useful information.
-
handleTokenNotFoundException
@ExceptionHandler(TokenNotFoundException.class) @ResponseStatus(NOT_FOUND) public org.springframework.http.ResponseEntity<Object> handleTokenNotFoundException(TokenNotFoundException ex) Handles the exception if the faces are not identical.- Parameters:
ex
- The exception is caused by the faces not being identical.- Returns:
- A readable
ResponseEntity
containing useful information.
-
handleTokenExpiredException
@ExceptionHandler(io.jsonwebtoken.ExpiredJwtException.class) @ResponseStatus(UNAUTHORIZED) public org.springframework.http.ResponseEntity<Object> handleTokenExpiredException(io.jsonwebtoken.ExpiredJwtException ex) Handles the exception if the JWT token has expired.- Parameters:
ex
- The exception is caused by the expired JWT token.- Returns:
- A readable
ResponseEntity
containing useful information.
-