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

@@ -28,7 +28,7 @@ public class DraftService {
@Transactional
public Draft saveDraft(String username, Long categoryId, String title, String content, List<Long> tagIds) {
User user = userRepository.findByUsername(username)
.orElseThrow(() -> new IllegalArgumentException("User not found"));
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
Draft draft = draftRepository.findByAuthor(user).orElse(new Draft());
draft.setAuthor(user);
draft.setTitle(title);