Skip to content

Commit

Permalink
Task 32 : Add Java Doc for GlobalExceptionHandler and RatelimiterAppl…
Browse files Browse the repository at this point in the history
…ication
  • Loading branch information
Rapter1990 committed Jul 2, 2024
1 parent da815d8 commit a44d13d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* Main class named {@link RatelimiterApplication} to start the Rate limiter application.
*/
@SpringBootApplication
public class RatelimiterApplication {

/**
* Main method to start the Spring Boot application.
*
* @param args the command line arguments
*/
public static void main(String[] args) {
SpringApplication.run(RatelimiterApplication.class, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,24 @@
import java.util.Map;
import java.util.stream.Collectors;

/**
* Global exception handler class named {@link GlobalExceptionHandler} for handling various exceptions across the application.
*/
@ControllerAdvice
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {

/**
* Handles MethodArgumentNotValidException and returns a custom error response with validation details.
*
* @param ex the exception thrown when method arguments are not valid
* @param headers the HTTP headers
* @param status the HTTP status code
* @param request the web request
* @return a ResponseEntity containing the custom error response
*/
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) {
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers,
HttpStatusCode status, WebRequest request) {

Map<String, String> errors = new HashMap<>();

Expand Down Expand Up @@ -56,7 +69,12 @@ protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotV
return new ResponseEntity<>(customError, HttpStatus.BAD_REQUEST);
}


/**
* Handles ConstraintViolationException and returns a custom error response with constraint violation details.
*
* @param constraintViolationException the exception thrown when constraint violations occur
* @return a ResponseEntity containing the custom error response
*/
@ExceptionHandler(ConstraintViolationException.class)
protected ResponseEntity<Object> handlePathVariableErrors(final ConstraintViolationException constraintViolationException) {

Expand Down Expand Up @@ -85,6 +103,12 @@ protected ResponseEntity<Object> handlePathVariableErrors(final ConstraintViolat

}

/**
* Handles RuntimeException and returns a custom error response.
*
* @param runtimeException the runtime exception thrown
* @return a ResponseEntity containing the custom error response
*/
@ExceptionHandler(RuntimeException.class)
protected ResponseEntity<?> handleRuntimeException(final RuntimeException runtimeException) {

Expand All @@ -99,6 +123,12 @@ protected ResponseEntity<?> handleRuntimeException(final RuntimeException runtim

}

/**
* Handles RateLimitExceededException and returns a custom error response.
*
* @param ex the exception thrown when rate limit is exceeded
* @return a ResponseEntity containing the custom error response
*/
@ExceptionHandler(RateLimitExceededException.class)
protected ResponseEntity<Object> handleRateLimitExceededException(final RateLimitExceededException ex) {

Expand All @@ -112,6 +142,12 @@ protected ResponseEntity<Object> handleRateLimitExceededException(final RateLimi
return new ResponseEntity<>(customError, HttpStatus.TOO_MANY_REQUESTS);
}

/**
* Handles EmailAlreadyExistsException and returns a custom error response.
*
* @param ex the exception thrown when an email already exists
* @return a ResponseEntity containing the custom error response
*/
@ExceptionHandler(EmailAlreadyExistsException.class)
protected ResponseEntity<Object> handleEmailAlreadyExistsException(final EmailAlreadyExistsException ex) {

Expand All @@ -125,6 +161,12 @@ protected ResponseEntity<Object> handleEmailAlreadyExistsException(final EmailAl
return new ResponseEntity<>(customError, HttpStatus.CONFLICT);
}

/**
* Handles UserNotFoundException and returns a custom error response.
*
* @param ex the exception thrown when a user is not found
* @return a ResponseEntity containing the custom error response
*/
@ExceptionHandler(UserNotFoundException.class)
protected ResponseEntity<Object> handleUserNotFoundException(final UserNotFoundException ex) {

Expand Down

0 comments on commit a44d13d

Please sign in to comment.