Package org.dspace.app.rest.exception
Class DSpaceApiExceptionControllerAdvice
java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
org.dspace.app.rest.exception.DSpaceApiExceptionControllerAdvice
- All Implemented Interfaces:
Aware,MessageSourceAware
@ControllerAdvice
public class DSpaceApiExceptionControllerAdvice
extends ResponseEntityExceptionHandler
This Controller advice will handle default exceptions thrown by the DSpace REST API module.
Keep in mind some specialized handlers exist for specific message types, e.g. DSpaceAccessDeniedHandler
- Author:
- Tom Desair (tom dot desair at atmire dot com), Frederic Van Reet (frederic dot vanreet at atmire dot com), Andrea Bollini (andrea.bollini at 4science.it), Pasquale Cavallo (pasquale.cavallo at 4science dot it)
- See Also:
-
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 voidcsrfTokenException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) protected voidhandleAuthorizeException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) protected voidhandleCustomUnprocessableEntityException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, TranslatableException ex) Add user-friendly error messages to the response body for selected errors.protected voidhandleGenericException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) protected voidhandleInvalidCaptchaTokenRequestException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) protected voidhandleInvalidPasswordException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) protected voidhandleInvalidSearchRequestException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) protected voidhandleIOException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) protected ResponseEntity<Object>handleMissingServletRequestParameter(MissingServletRequestParameterException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) protected voidhandleOrcidValidationException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, OrcidValidationException ex) Handle theOrcidValidationExceptionreturning the exception message in the response, that always contains only the validation error codes (usable for example to show specific messages to users).protected voidhandleSQLException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) protected ResponseEntity<Object>handleTypeMismatch(TypeMismatchException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) protected voidhandleUnprocessableEntityException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) protected voidhandleWrongRequestException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) protected voidmethodNotAllowedException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) protected voidMissingParameterException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) protected voidParameterConversionException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) Methods inherited from class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
createProblemDetail, createResponseEntity, getMessageSource, handleAsyncRequestNotUsableException, handleAsyncRequestTimeoutException, handleConversionNotSupported, handleErrorResponseException, handleException, handleExceptionInternal, handleHandlerMethodValidationException, handleHttpMediaTypeNotAcceptable, handleHttpMediaTypeNotSupported, handleHttpMessageNotReadable, handleHttpMessageNotWritable, handleHttpRequestMethodNotSupported, handleMaxUploadSizeExceededException, handleMethodArgumentNotValid, handleMethodValidationException, handleMissingPathVariable, handleMissingServletRequestPart, handleNoHandlerFoundException, handleNoResourceFoundException, handleServletRequestBindingException, setMessageSource
-
Constructor Details
-
DSpaceApiExceptionControllerAdvice
public DSpaceApiExceptionControllerAdvice()
-
-
Method Details
-
handleAuthorizeException
@ExceptionHandler({org.dspace.authorize.AuthorizeException.class,RESTAuthorizationException.class,org.springframework.security.access.AccessDeniedException.class}) protected void handleAuthorizeException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) throws IOException - Throws:
IOException
-
csrfTokenException
@ExceptionHandler({org.springframework.security.web.csrf.InvalidCsrfTokenException.class,org.springframework.security.web.csrf.MissingCsrfTokenException.class}) protected void csrfTokenException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) throws IOException - Throws:
IOException
-
handleWrongRequestException
@ExceptionHandler({java.lang.IllegalArgumentException.class,org.springframework.web.multipart.MultipartException.class,InvalidLDNMessageException.class}) protected void handleWrongRequestException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) throws IOException - Throws:
IOException
-
handleSQLException
@ExceptionHandler(java.sql.SQLException.class) protected void handleSQLException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) throws IOException - Throws:
IOException
-
handleIOException
@ExceptionHandler(java.io.IOException.class) protected void handleIOException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) throws IOException - Throws:
IOException
-
methodNotAllowedException
@ExceptionHandler(MethodNotAllowedException.class) protected void methodNotAllowedException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) throws IOException - Throws:
IOException
-
handleUnprocessableEntityException
@ExceptionHandler({UnprocessableEntityException.class,org.dspace.app.exception.ResourceAlreadyExistsException.class}) protected void handleUnprocessableEntityException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) throws IOException - Throws:
IOException
-
handleInvalidSearchRequestException
@ExceptionHandler(InvalidSearchRequestException.class) protected void handleInvalidSearchRequestException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) throws IOException - Throws:
IOException
-
handleOrcidValidationException
@ExceptionHandler(org.dspace.orcid.exception.OrcidValidationException.class) protected void handleOrcidValidationException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, OrcidValidationException ex) throws IOException Handle theOrcidValidationExceptionreturning the exception message in the response, that always contains only the validation error codes (usable for example to show specific messages to users). No other details are present in the exception message.- Throws:
IOException
-
handleCustomUnprocessableEntityException
@ExceptionHandler({RESTEmptyWorkflowGroupException.class,EPersonNameNotProvidedException.class,GroupNameNotProvidedException.class,GroupHasPendingWorkflowTasksException.class,PasswordNotValidException.class,RESTBitstreamNotFoundException.class}) protected void handleCustomUnprocessableEntityException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, TranslatableException ex) throws IOException Add user-friendly error messages to the response body for selected errors. Since the error messages will be exposed to the API user, the exception classes are expected to implementTranslatableExceptionsuch that the error messages can be translated.- Parameters:
request- the client's requestresponse- our responseex- exception thrown in handling request- Throws:
IOException- passed through.
-
ParameterConversionException
@ExceptionHandler(org.springframework.data.repository.support.QueryMethodParameterConversionException.class) protected void ParameterConversionException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) throws IOException - Throws:
IOException
-
MissingParameterException
@ExceptionHandler(MissingParameterException.class) protected void MissingParameterException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) throws IOException - Throws:
IOException
-
handleInvalidPasswordException
@ExceptionHandler(WrongCurrentPasswordException.class) protected void handleInvalidPasswordException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) throws IOException - Throws:
IOException
-
handleInvalidCaptchaTokenRequestException
@ExceptionHandler(org.dspace.eperson.InvalidReCaptchaException.class) protected void handleInvalidCaptchaTokenRequestException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) throws IOException - Throws:
IOException
-
handleMissingServletRequestParameter
protected ResponseEntity<Object> handleMissingServletRequestParameter(MissingServletRequestParameterException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) - Overrides:
handleMissingServletRequestParameterin classResponseEntityExceptionHandler
-
handleTypeMismatch
protected ResponseEntity<Object> handleTypeMismatch(TypeMismatchException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) - Overrides:
handleTypeMismatchin classResponseEntityExceptionHandler
-
handleGenericException
@ExceptionHandler(java.lang.Exception.class) protected void handleGenericException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Exception ex) throws IOException - Throws:
IOException
-