Return 404 when user or post not found

This commit is contained in:
Tim
2025-07-14 19:24:11 +08:00
parent f4cedc3a4f
commit aed3c87e4a
12 changed files with 53 additions and 37 deletions

View File

@@ -4,6 +4,7 @@ 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 com.openisle.exception.NotFoundException;
import java.util.Map;
@@ -16,6 +17,11 @@ public class GlobalExceptionHandler {
.body(Map.of("error", ex.getMessage(), "field", ex.getField()));
}
@ExceptionHandler(NotFoundException.class)
public ResponseEntity<?> handleNotFoundException(NotFoundException ex) {
return ResponseEntity.status(404).body(Map.of("error", ex.getMessage()));
}
@ExceptionHandler(Exception.class)
public ResponseEntity<?> handleException(Exception ex) {
return ResponseEntity.badRequest().body(Map.of("error", ex.getMessage()));