Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

refactor(account): share the alternate-contact not-found exception (#5755)

Matheus Oliveira01cc020419e1
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);
+ }
}