feat: improve registration validation

This commit is contained in:
Tim
2025-07-04 22:15:05 +08:00
parent b17df96060
commit 968341dcb1
5 changed files with 79 additions and 11 deletions

View File

@@ -3,12 +3,19 @@ package com.openisle.controller;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import com.openisle.exception.FieldException;
import java.util.Map;
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(FieldException.class)
public ResponseEntity<?> handleFieldException(FieldException ex) {
return ResponseEntity.badRequest()
.body(Map.of("error", ex.getMessage(), "field", ex.getField()));
}
@ExceptionHandler(Exception.class)
public ResponseEntity<?> handleException(Exception ex) {
return ResponseEntity.badRequest().body(Map.of("error", ex.getMessage()));