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 <matheus.6148@gmail.com>
This commit is contained in:
Matheus Oliveira authored and GitHub committed 2026-10-15 18:59:10 -04:00
1 parent 945f5d3995
commit 01cc020419
1 file changed
+8 -6
@@ -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);
}
}