From 797d482ebff55f88b13c4f92f59584ad7dcf3379 Mon Sep 17 00:00:00 2001 From: Cedric Hornberger Date: Tue, 5 May 2026 16:55:01 +0200 Subject: [PATCH] fix: use ResourceNotFoundException for not-found cases in updateExpense, IllegalArgumentException for ownership mismatch in deleteCustomCategory --- .../app/xpensely_server/services/ExpenseListService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/zendric/app/xpensely_server/services/ExpenseListService.java b/src/main/java/de/zendric/app/xpensely_server/services/ExpenseListService.java index 284e89f..0f65b6e 100644 --- a/src/main/java/de/zendric/app/xpensely_server/services/ExpenseListService.java +++ b/src/main/java/de/zendric/app/xpensely_server/services/ExpenseListService.java @@ -117,7 +117,7 @@ public class ExpenseListService { public Expense updateExpense(Long expenseListId, Expense updatedExpense) { ExpenseList expenseList = repository.findById(expenseListId) - .orElseThrow(() -> new IllegalArgumentException("ExpenseList not found")); + .orElseThrow(() -> new ResourceNotFoundException("ExpenseList not found with id: " + expenseListId)); if (!expenseList.getExpenses().stream() .anyMatch(expense -> expense.getId().equals(updatedExpense.getId()))) { @@ -125,7 +125,7 @@ public class ExpenseListService { } Expense existingExpense = expenseRepository.findById(updatedExpense.getId()) - .orElseThrow(() -> new IllegalArgumentException("Expense not found")); + .orElseThrow(() -> new ResourceNotFoundException("Expense not found with id: " + updatedExpense.getId())); existingExpense.setTitle(updatedExpense.getTitle()); existingExpense.setAmount(updatedExpense.getAmount()); existingExpense.setPersonalUseAmount(updatedExpense.getPersonalUseAmount()); @@ -151,7 +151,7 @@ public class ExpenseListService { XpenselyCustomCategory category = customCategoryRepository.findById(categoryId) .orElseThrow(() -> new ResourceNotFoundException("Custom Category not found")); if (!category.getExpenseList().getId().equals(expenseListId)) { - throw new RuntimeException("Category does not belong to the specified Expense List"); + throw new IllegalArgumentException("Category does not belong to the specified Expense List"); } customCategoryRepository.delete(category); }