Class CrudCraftExceptionHandler

java.lang.Object
nl.datasteel.crudcraft.runtime.controller.CrudCraftExceptionHandler

@RestControllerAdvice public class CrudCraftExceptionHandler extends Object
Central @RestControllerAdvice for translating exceptions into HTTP responses.
  • Constructor Details

    • CrudCraftExceptionHandler

      public CrudCraftExceptionHandler()
  • Method Details

    • handleNotFound

      @ExceptionHandler(ResourceNotFoundException.class) public org.springframework.http.ResponseEntity<ErrorResponse> handleNotFound(ResourceNotFoundException ex, jakarta.servlet.http.HttpServletRequest req)
      Handles ResourceNotFoundException and returns a 404 Not Found response.
      Parameters:
      ex - the exception
      req - the HTTP request
      Returns:
      ResponseEntity with ErrorResponse
    • handleConflict

      @ExceptionHandler({DuplicateResourceException.class,DataIntegrityException.class}) public org.springframework.http.ResponseEntity<ErrorResponse> handleConflict(RuntimeException ex, jakarta.servlet.http.HttpServletRequest req)
      Handles DuplicateResourceException and DataIntegrityException, returning a 409 Conflict response.
      Parameters:
      ex - the exception
      req - the HTTP request
      Returns:
      ResponseEntity with ErrorResponse
    • handleBadRequest

      @ExceptionHandler(BadRequestException.class) public org.springframework.http.ResponseEntity<ErrorResponse> handleBadRequest(BadRequestException ex, jakarta.servlet.http.HttpServletRequest req)
      Handles BadRequestException and returns a 400 Bad Request response.
      Parameters:
      ex - the exception
      req - the HTTP request
      Returns:
      ResponseEntity with ErrorResponse
    • handleUnauthorized

      @ExceptionHandler(UnauthorizedException.class) public org.springframework.http.ResponseEntity<ErrorResponse> handleUnauthorized(UnauthorizedException ex, jakarta.servlet.http.HttpServletRequest req)
      Handles UnauthorizedException and returns a 401 Unauthorized response.
      Parameters:
      ex - the exception
      req - the HTTP request
      Returns:
      ResponseEntity with ErrorResponse
    • handleForbidden

      @ExceptionHandler(ForbiddenException.class) public org.springframework.http.ResponseEntity<ErrorResponse> handleForbidden(ForbiddenException ex, jakarta.servlet.http.HttpServletRequest req)
      Handles ForbiddenException and returns a 403 Forbidden response.
      Parameters:
      ex - the exception
      req - the HTTP request
      Returns:
      ResponseEntity with ErrorResponse
    • handleMethodNotAllowed

      @ExceptionHandler(OperationNotAllowedException.class) public org.springframework.http.ResponseEntity<ErrorResponse> handleMethodNotAllowed(OperationNotAllowedException ex, jakarta.servlet.http.HttpServletRequest req)
      Handles MethodNotAllowedException and returns a 405 Method Not Allowed response.
      Parameters:
      ex - the exception
      req - the HTTP request
      Returns:
      ResponseEntity with ErrorResponse
    • handlePreconditionFailed

      @ExceptionHandler(PreconditionFailedException.class) public org.springframework.http.ResponseEntity<ErrorResponse> handlePreconditionFailed(PreconditionFailedException ex, jakarta.servlet.http.HttpServletRequest req)
      Handles PreconditionFailedException and returns a 412 Precondition Failed response.
      Parameters:
      ex - the exception
      req - the HTTP request
      Returns:
      ResponseEntity with ErrorResponse
    • handleNotImplemented

      @ExceptionHandler(NotImplementedException.class) public org.springframework.http.ResponseEntity<ErrorResponse> handleNotImplemented(NotImplementedException ex, jakarta.servlet.http.HttpServletRequest req)
      Handles NotImplementedException and returns a 501 Not Implemented response.
      Parameters:
      ex - the exception
      req - the HTTP request
      Returns:
      ResponseEntity with ErrorResponse
    • handleTooManyRequests

      @ExceptionHandler(TooManyRequestsException.class) public org.springframework.http.ResponseEntity<ErrorResponse> handleTooManyRequests(TooManyRequestsException ex, jakarta.servlet.http.HttpServletRequest req)
      Handles TooManyRequestsException and returns a 429 Too Many Requests response.
      Parameters:
      ex - the exception
      req - the HTTP request
      Returns:
      ResponseEntity with ErrorResponse
    • handleBulk

      @ExceptionHandler(BulkOperationException.class) public org.springframework.http.ResponseEntity<List<ErrorResponse>> handleBulk(BulkOperationException ex, jakarta.servlet.http.HttpServletRequest req)
      Handles BulkOperationException and returns a 207 Multi-Status response with a list of errors.
      Parameters:
      ex - the exception
      req - the HTTP request
      Returns:
      ResponseEntity with a list of ErrorResponse
    • handleCrudCraftErrors

      @ExceptionHandler(CrudCraftRuntimeException.class) public org.springframework.http.ResponseEntity<ErrorResponse> handleCrudCraftErrors(CrudCraftRuntimeException ex, jakarta.servlet.http.HttpServletRequest req)
      Handles CrudCraftRuntimeException and returns a 500 Internal Server Error response.
      Parameters:
      ex - the exception
      req - the HTTP request
      Returns:
      ResponseEntity with ErrorResponse
    • handleEverythingElse

      @ExceptionHandler(java.lang.Exception.class) public org.springframework.http.ResponseEntity<ErrorResponse> handleEverythingElse(Exception ex, jakarta.servlet.http.HttpServletRequest req)
      Handles any other unexpected exceptions and returns a 500 Internal Server Error response.
      Parameters:
      ex - the exception
      req - the HTTP request
      Returns:
      ResponseEntity with ErrorResponse