Klasse GlobalExceptionHandler
java.lang.Object
com.spaghetticodegang.trylater.shared.exception.GlobalExceptionHandler
Global exception handler for the application.
Catches and handles common exceptions thrown across controllers and returns
structured error responses with meaningful messages.
-
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungorg.springframework.http.ResponseEntity
<Object> handleBadCredentials
(org.springframework.security.authentication.BadCredentialsException ex) Handles authentication failures caused by incorrect passwords.org.springframework.http.ResponseEntity
<Object> Handles authentication failures caused by non-existent contacts.org.springframework.http.ResponseEntity
<Object> Handles failures caused by ioException while handling an image.org.springframework.http.ResponseEntity
<Object> handleMaxSizeException
(org.springframework.web.multipart.MaxUploadSizeExceededException ex) Handles failures caused by exceeding image size upload limit.org.springframework.http.ResponseEntity
<Object> handleMethodArgumentNotValid
(org.springframework.web.bind.MethodArgumentNotValidException ex) Handles validation errors triggered by@Valid
annotated parameters.org.springframework.http.ResponseEntity
<Object> handleMethodArgumentTypeMismatch
(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException ex) Handles type mismatch errors in request parameters, e.g. invalid enum values.org.springframework.http.ResponseEntity
<Object> handleMissingServletRequestParameter
(org.springframework.web.bind.MissingServletRequestParameterException ex) Handles missing request parameters, especially for required query parameters.org.springframework.http.ResponseEntity
<Object> Handles all other unhandled exceptions.org.springframework.http.ResponseEntity
<Object> Handles authentication failures caused by non-existent recommendation assignment.org.springframework.http.ResponseEntity
<Object> Handles authentication failures caused by incorrect password.org.springframework.http.ResponseEntity
<Object> Handles authentication failures caused by non-existent recommendation.org.springframework.http.ResponseEntity
<Object> Handles uncaughtRuntimeException
instances.org.springframework.http.ResponseEntity
<Object> handleUsernameNotFound
(org.springframework.security.core.userdetails.UsernameNotFoundException ex) Handles authentication failures caused by non-existent usernames.org.springframework.http.ResponseEntity
<Object> Handles customValidationException
thrown within business logic.
-
Konstruktordetails
-
GlobalExceptionHandler
public GlobalExceptionHandler()
-
-
Methodendetails
-
handleMethodArgumentNotValid
@ExceptionHandler(org.springframework.web.bind.MethodArgumentNotValidException.class) public org.springframework.http.ResponseEntity<Object> handleMethodArgumentNotValid(org.springframework.web.bind.MethodArgumentNotValidException ex) Handles validation errors triggered by@Valid
annotated parameters.- Parameter:
ex
- the exception containing field validation errors- Gibt zurück:
- a 400 Bad Request response with field-specific error messages
-
handleBadCredentials
@ExceptionHandler(org.springframework.security.authentication.BadCredentialsException.class) public org.springframework.http.ResponseEntity<Object> handleBadCredentials(org.springframework.security.authentication.BadCredentialsException ex) Handles authentication failures caused by incorrect passwords.- Parameter:
ex
- the exception thrown when credentials are invalid- Gibt zurück:
- a 400 Bad Request response with a user-friendly error message
-
handleUsernameNotFound
@ExceptionHandler(org.springframework.security.core.userdetails.UsernameNotFoundException.class) public org.springframework.http.ResponseEntity<Object> handleUsernameNotFound(org.springframework.security.core.userdetails.UsernameNotFoundException ex) Handles authentication failures caused by non-existent usernames.- Parameter:
ex
- the exception thrown when the user is not found- Gibt zurück:
- a 404 Not Found response with a user-friendly error message
-
handleMaxSizeException
@ExceptionHandler(org.springframework.web.multipart.MaxUploadSizeExceededException.class) public org.springframework.http.ResponseEntity<Object> handleMaxSizeException(org.springframework.web.multipart.MaxUploadSizeExceededException ex) Handles failures caused by exceeding image size upload limit.- Parameter:
ex
- the exception thrown when the image size is too big- Gibt zurück:
- a 413 Payload Too Large response with a user-friendly error message
-
handleMethodArgumentTypeMismatch
@ExceptionHandler(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException.class) public org.springframework.http.ResponseEntity<Object> handleMethodArgumentTypeMismatch(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException ex) Handles type mismatch errors in request parameters, e.g. invalid enum values.- Parameter:
ex
- the exception describing the parameter mismatch- Gibt zurück:
- a 400 Bad Request response with a specific message for known types
-
handleMissingServletRequestParameter
@ExceptionHandler(org.springframework.web.bind.MissingServletRequestParameterException.class) public org.springframework.http.ResponseEntity<Object> handleMissingServletRequestParameter(org.springframework.web.bind.MissingServletRequestParameterException ex) Handles missing request parameters, especially for required query parameters.- Parameter:
ex
- the exception describing the missing parameter- Gibt zurück:
- a 400 Bad Request response with a parameter-specific or general error message
-
handleRuntimeException
@ExceptionHandler(RuntimeException.class) public org.springframework.http.ResponseEntity<Object> handleRuntimeException(RuntimeException ex) Handles uncaughtRuntimeException
instances.- Parameter:
ex
- the runtime exception- Gibt zurück:
- a 400 Bad Request response
-
handleOtherExceptions