Add exceptions

This commit is contained in:
Ivan Zinchenko 2026-01-10 15:52:29 +03:00
parent cef6fd99c6
commit db151b4fd9
Signed by: zinch
GPG Key ID: 6D45AA2C8FD6A37E
3 changed files with 16 additions and 2 deletions

View File

@ -47,6 +47,20 @@ public class GlobalExceptionHandler {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(ApiResponse.error(error));
}
@ExceptionHandler(TOTPRequiredException.class)
public ResponseEntity<ApiResponse<Void>> 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<ApiResponse<Void>> 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<ApiResponse<Void>> handleGenericException(Exception e) {
log.error("Unexpected error: ", e);

View File

@ -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);
}

View File

@ -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);
}