mirror of
https://github.com/floci-io/floci.git
synced 2026-11-30 08:55:17 -05:00
fix(redshift-serverless): return HTTP 400 for ResourceNotFoundException and ConflictException (#5409)
This commit is contained in:
1 parent
58ac05433a
commit
972ff03f00
5 files changed
+46
-37
No files matched your search
+19
-17
@@ -216,8 +216,7 @@ public class RedshiftServerlessService implements Resettable {
|
||||
validateNamespaceName(namespaceName);
|
||||
String key = storageKey(region, namespaceName);
|
||||
if (namespaces.get(key).isPresent()) {
|
||||
throw new AwsException("ConflictException",
|
||||
"The namespace " + namespaceName + " already exists.", 409);
|
||||
throw conflict("The namespace " + namespaceName + " already exists.");
|
||||
}
|
||||
|
||||
Namespace namespace = new Namespace();
|
||||
@@ -340,8 +339,7 @@ public class RedshiftServerlessService implements Resettable {
|
||||
// A workgroup cannot outlive its namespace; the model lists ConflictException for this call
|
||||
// but not its trigger, so this guard is the single place to relax if AWS turns out to differ.
|
||||
if (workgroupOf(namespaceName, region).isPresent()) {
|
||||
throw new AwsException("ConflictException",
|
||||
"The namespace " + namespaceName + " still has a workgroup. Delete the workgroup first.", 409);
|
||||
throw conflict("The namespace " + namespaceName + " still has a workgroup. Delete the workgroup first.");
|
||||
}
|
||||
namespaces.delete(storageKey(region, namespaceName));
|
||||
deleted.setStatus("DELETING");
|
||||
@@ -363,8 +361,7 @@ public class RedshiftServerlessService implements Resettable {
|
||||
Namespace namespace = getNamespace(namespaceName, region);
|
||||
String key = storageKey(region, snapshotName);
|
||||
if (snapshots.get(key).isPresent()) {
|
||||
throw new AwsException("ConflictException",
|
||||
"The snapshot " + snapshotName + " already exists.", 409);
|
||||
throw conflict("The snapshot " + snapshotName + " already exists.");
|
||||
}
|
||||
RedshiftServerlessSnapshot snapshot = new RedshiftServerlessSnapshot();
|
||||
snapshot.setSnapshotName(snapshotName);
|
||||
@@ -459,8 +456,7 @@ public class RedshiftServerlessService implements Resettable {
|
||||
public RedshiftServerlessSnapshot getSnapshot(String snapshotName, String region) {
|
||||
requireSnapshotName(snapshotName);
|
||||
return snapshots.get(storageKey(region, snapshotName))
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"The snapshot " + snapshotName + " was not found.", 404));
|
||||
.orElseThrow(() -> snapshotNotFound(snapshotName));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -516,8 +512,7 @@ public class RedshiftServerlessService implements Resettable {
|
||||
validateNamespaceName(namespaceName);
|
||||
RedshiftServerlessSnapshot snapshot = getSnapshot(snapshotName, region);
|
||||
if (ownerAccount != null && !ownerAccount.isBlank() && !ownerAccount.equals(snapshot.getOwnerAccount())) {
|
||||
throw new AwsException("ResourceNotFoundException",
|
||||
"The snapshot " + snapshotName + " was not found.", 404);
|
||||
throw snapshotNotFound(snapshotName);
|
||||
}
|
||||
Workgroup workgroup = getWorkgroup(workgroupName, region);
|
||||
if (!namespaceName.equals(workgroup.getNamespaceName())) {
|
||||
@@ -641,7 +636,7 @@ public class RedshiftServerlessService implements Resettable {
|
||||
|
||||
private static AwsException resourceNotFound(String resourceArn) {
|
||||
return new AwsException("ResourceNotFoundException",
|
||||
"The resource " + resourceArn + " was not found.", 404);
|
||||
"The resource " + resourceArn + " was not found.", 400);
|
||||
}
|
||||
|
||||
public synchronized Workgroup createWorkgroup(String workgroupName, String namespaceName,
|
||||
@@ -652,12 +647,10 @@ public class RedshiftServerlessService implements Resettable {
|
||||
Namespace namespace = getNamespace(namespaceName, region);
|
||||
String key = storageKey(region, workgroupName);
|
||||
if (workgroups.get(key).isPresent()) {
|
||||
throw new AwsException("ConflictException",
|
||||
"The workgroup " + workgroupName + " already exists.", 409);
|
||||
throw conflict("The workgroup " + workgroupName + " already exists.");
|
||||
}
|
||||
if (workgroupOf(namespaceName, region).isPresent()) {
|
||||
throw new AwsException("ConflictException",
|
||||
"The namespace " + namespaceName + " already has a workgroup.", 409);
|
||||
throw conflict("The namespace " + namespaceName + " already has a workgroup.");
|
||||
}
|
||||
|
||||
Workgroup workgroup = new Workgroup();
|
||||
@@ -1022,7 +1015,7 @@ public class RedshiftServerlessService implements Resettable {
|
||||
|
||||
private static AwsException workgroupNotFound(String workgroupName) {
|
||||
return new AwsException("ResourceNotFoundException",
|
||||
"The workgroup " + workgroupName + " was not found.", 404);
|
||||
"The workgroup " + workgroupName + " was not found.", 400);
|
||||
}
|
||||
|
||||
private static String storageKey(String region, String namespaceName) {
|
||||
@@ -1031,7 +1024,16 @@ public class RedshiftServerlessService implements Resettable {
|
||||
|
||||
private static AwsException notFound(String namespaceName) {
|
||||
return new AwsException("ResourceNotFoundException",
|
||||
"The namespace " + namespaceName + " was not found.", 404);
|
||||
"The namespace " + namespaceName + " was not found.", 400);
|
||||
}
|
||||
|
||||
private static AwsException snapshotNotFound(String snapshotName) {
|
||||
return new AwsException("ResourceNotFoundException",
|
||||
"The snapshot " + snapshotName + " was not found.", 400);
|
||||
}
|
||||
|
||||
private static AwsException conflict(String message) {
|
||||
return new AwsException("ConflictException", message, 400);
|
||||
}
|
||||
|
||||
private static AwsException validation(String message) {
|
||||
|
||||
Reference in new issue
Block a user