From 01cc020419e18246fa137bf7ac4eec7c1783fa60 Mon Sep 17 00:00:00 2001 From: Matheus Oliveira <99829531+omatheusmesmo@users.noreply.github.com> Date: Thu, 15 Oct 2026 19:59:10 -0300 Subject: [PATCH] refactor(account): share the alternate-contact not-found exception (#5755) getAlternateContact and deleteAlternateContact each built the same ResourceNotFoundException. Move it into a notFound() helper next to validation() so the two stay in step. Follow-up to #5560. Signed-off-by: Matheus Oliveira --- .../floci/services/account/AccountService.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/github/hectorvent/floci/services/account/AccountService.java b/src/main/java/io/github/hectorvent/floci/services/account/AccountService.java index c21d5452b7..24c6bec4f0 100644 --- a/src/main/java/io/github/hectorvent/floci/services/account/AccountService.java +++ b/src/main/java/io/github/hectorvent/floci/services/account/AccountService.java @@ -52,17 +52,14 @@ public class AccountService implements Resettable { String targetAccountId = resolveTargetAccount(callerAccountId, request); String type = requireContactType(request); return contacts.getForAccount(targetAccountId, type) - .orElseThrow(() -> new AwsException("ResourceNotFoundException", - "The alternate contact does not exist for the specified account and contact type.", 404)); + .orElseThrow(AccountService::notFound); } public synchronized void deleteAlternateContact(String callerAccountId, JsonNode request) { String targetAccountId = resolveTargetAccount(callerAccountId, request); String type = requireContactType(request); - boolean exists = contacts.getForAccount(targetAccountId, type).isPresent(); - if (!exists) { - throw new AwsException("ResourceNotFoundException", - "The alternate contact does not exist for the specified account and contact type.", 404); + if (contacts.getForAccount(targetAccountId, type).isEmpty()) { + throw notFound(); } contacts.deleteForAccount(targetAccountId, type); } @@ -151,4 +148,9 @@ public class AccountService implements Resettable { private static AwsException validation(String message) { return new AwsException("ValidationException", message, 400); } + + private static AwsException notFound() { + return new AwsException("ResourceNotFoundException", + "The alternate contact does not exist for the specified account and contact type.", 404); + } }