fix(sqs): translate Query-protocol error codes to JSON __type equivalents (#59)

The AWS SDK v2 uses the __type field in JSON error responses to instantiate
typed exceptions. Query-protocol codes such as
AWS.SimpleQueueService.NonExistentQueue were being forwarded verbatim into
the JSON __type field, causing the SDK to fall back to a generic SqsException
instead of QueueDoesNotExistException.

Add a jsonType() method to AwsException that maps Query-protocol codes to
their JSON-protocol equivalents (e.g. QueueDoesNotExist, QueueNameExists).
Both AwsExceptionMapper and the inline catch in AwsJsonController now call
jsonType() so the mapping is applied consistently across all code paths.
This commit is contained in:
Roberto Perez Alcolea authored and GitHub committed 2026-03-31 17:10:18 -05:00
1 parent ff2f68d8ab
commit 7d6cf6179d
4 files changed
+120 -3

No files matched your search

@@ -1,6 +1,9 @@
package io.github.hectorvent.floci.services.sqs;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.config.EncoderConfig;
import io.restassured.http.ContentType;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
@@ -215,4 +218,92 @@ class SqsIntegrationTest {
.statusCode(400)
.body(containsString("UnsupportedOperation"));
}
@Test
void createQueue_idempotent_sameAttributes() {
String queueName = "idempotent-test-queue";
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateQueue")
.formParam("QueueName", queueName)
.formParam("Attribute.1.Name", "VisibilityTimeout")
.formParam("Attribute.1.Value", "60")
.when()
.post("/")
.then()
.statusCode(200)
.body(containsString(queueName));
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateQueue")
.formParam("QueueName", queueName)
.formParam("Attribute.1.Name", "VisibilityTimeout")
.formParam("Attribute.1.Value", "60")
.when()
.post("/")
.then()
.statusCode(200)
.body(containsString(queueName));
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DeleteQueue")
.formParam("QueueUrl", "http://localhost:4566/000000000000/" + queueName)
.when()
.post("/");
}
@Test
void createQueue_conflictingAttributes_returns400() {
String queueName = "conflict-test-queue";
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateQueue")
.formParam("QueueName", queueName)
.formParam("Attribute.1.Name", "VisibilityTimeout")
.formParam("Attribute.1.Value", "30")
.when()
.post("/")
.then()
.statusCode(200);
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateQueue")
.formParam("QueueName", queueName)
.formParam("Attribute.1.Name", "VisibilityTimeout")
.formParam("Attribute.1.Value", "60")
.when()
.post("/")
.then()
.statusCode(400)
.body(containsString("QueueNameExists"));
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DeleteQueue")
.formParam("QueueUrl", "http://localhost:4566/000000000000/" + queueName)
.when()
.post("/");
}
@Test
void jsonProtocol_nonExistentQueue_returnsQueueDoesNotExist() {
given()
.config(RestAssured.config().encoderConfig(
EncoderConfig.encoderConfig()
.encodeContentTypeAs("application/x-amz-json-1.0", ContentType.TEXT)))
.contentType("application/x-amz-json-1.0")
.header("X-Amz-Target", "AmazonSQS.GetQueueUrl")
.body("{\"QueueName\": \"no-such-queue-xyz\"}")
.when()
.post("/")
.then()
.statusCode(400)
.body(containsString("QueueDoesNotExist"))
.body(not(containsString("AWS.SimpleQueueService.NonExistentQueue")));
}
}