diff --git a/auth-service/src/main/java/ru/itmo/auth/exception/GlobalExceptionHandler.java b/auth-service/src/main/java/ru/itmo/auth/exception/GlobalExceptionHandler.java index 405e41b..dfd9d86 100644 --- a/auth-service/src/main/java/ru/itmo/auth/exception/GlobalExceptionHandler.java +++ b/auth-service/src/main/java/ru/itmo/auth/exception/GlobalExceptionHandler.java @@ -47,6 +47,20 @@ public class GlobalExceptionHandler { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(ApiResponse.error(error)); } + @ExceptionHandler(TOTPRequiredException.class) + public ResponseEntity> handleTotpRequired(TOTPRequiredException e) { + log.error("TOTP required: {}", e.getMessage()); + ApiError error = new ApiError("TOTP_REQUIRED", e.getMessage()); + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(ApiResponse.error(error)); + } + + @ExceptionHandler(InvalidTOTPException.class) + public ResponseEntity> handleInvalidTotp(InvalidTOTPException e) { + log.error("Invalid TOTP: {}", e.getMessage()); + ApiError error = new ApiError("INVALID_TOTP", e.getMessage()); + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(ApiResponse.error(error)); + } + @ExceptionHandler(Exception.class) public ResponseEntity> handleGenericException(Exception e) { log.error("Unexpected error: ", e); diff --git a/auth-service/src/main/java/ru/itmo/auth/exception/InvalidTOTPException.java b/auth-service/src/main/java/ru/itmo/auth/exception/InvalidTOTPException.java index 393f6ff..4f50311 100644 --- a/auth-service/src/main/java/ru/itmo/auth/exception/InvalidTOTPException.java +++ b/auth-service/src/main/java/ru/itmo/auth/exception/InvalidTOTPException.java @@ -1,6 +1,6 @@ package ru.itmo.auth.exception; -public class InvalidTOTPException extends RuntimeException{ +public class InvalidTOTPException extends RuntimeException { public InvalidTOTPException(String message) { super(message); } diff --git a/auth-service/src/main/java/ru/itmo/auth/exception/TOTPRequiredException.java b/auth-service/src/main/java/ru/itmo/auth/exception/TOTPRequiredException.java index 11d38ef..8ad8ae1 100644 --- a/auth-service/src/main/java/ru/itmo/auth/exception/TOTPRequiredException.java +++ b/auth-service/src/main/java/ru/itmo/auth/exception/TOTPRequiredException.java @@ -1,6 +1,6 @@ package ru.itmo.auth.exception; -public class TOTPRequiredException extends RuntimeException{ +public class TOTPRequiredException extends RuntimeException { public TOTPRequiredException(String message) { super(message); }