@@ -23,6 +23,7 @@ import com.amplifyframework.testutils.Await
2323import io.kotest.matchers.nulls.shouldNotBeNull
2424import io.kotest.matchers.shouldBe
2525import io.kotest.matchers.types.shouldBeInstanceOf
26+ import java.io.IOException
2627import okhttp3.HttpUrl
2728import okhttp3.mockwebserver.MockResponse
2829import okhttp3.mockwebserver.MockWebServer
@@ -33,7 +34,6 @@ import org.junit.Before
3334import org.junit.Test
3435import org.junit.runner.RunWith
3536import org.robolectric.RobolectricTestRunner
36- import java.io.IOException
3737
3838/* *
3939 * Integration tests for error cause propagation in GraphQL operations.
@@ -59,12 +59,15 @@ class AppSyncErrorPropagationTest {
5959 baseUrl = webServer.url(" /" )
6060
6161 val configuration = JSONObject ()
62- .put(" graphQlApi" , JSONObject ()
63- .put(" endpointType" , " GraphQL" )
64- .put(" endpoint" , baseUrl.toUrl())
65- .put(" region" , " us-east-1" )
66- .put(" authorizationType" , " API_KEY" )
67- .put(" apiKey" , " FAKE-API-KEY" ))
62+ .put(
63+ " graphQlApi" ,
64+ JSONObject ()
65+ .put(" endpointType" , " GraphQL" )
66+ .put(" endpoint" , baseUrl.toUrl())
67+ .put(" region" , " us-east-1" )
68+ .put(" authorizationType" , " API_KEY" )
69+ .put(" apiKey" , " FAKE-API-KEY" )
70+ )
6871
6972 plugin = AWSApiPlugin .builder().build()
7073 plugin.configure(configuration, ApplicationProvider .getApplicationContext())
@@ -95,10 +98,12 @@ class AppSyncErrorPropagationTest {
9598 }]
9699 }
97100 """ .trimIndent()
98-
99- webServer.enqueue(MockResponse ()
100- .setResponseCode(401 )
101- .setBody(errorResponse))
101+
102+ webServer.enqueue(
103+ MockResponse ()
104+ .setResponseCode(401 )
105+ .setBody(errorResponse)
106+ )
102107
103108 // Act - execute query and capture error
104109 val error = Await .error { onResult, onError ->
@@ -108,13 +113,13 @@ class AppSyncErrorPropagationTest {
108113 // Assert - verify error has proper cause chain
109114 error.shouldNotBeNull()
110115 error.shouldBeInstanceOf<ApiException .NonRetryableException >()
111-
116+
112117 val cause = error.cause
113118 cause.shouldNotBeNull()
114119 cause.shouldBeInstanceOf<GraphQLResponseException >()
115120
116121 cause.errors.size.shouldBe(1 )
117-
122+
118123 val firstError = cause.errors[0 ]
119124 firstError.errorType.shouldBe(" UnauthorizedException" )
120125 firstError.message.shouldBe(" You are not authorized to make this call." )
@@ -127,10 +132,12 @@ class AppSyncErrorPropagationTest {
127132 fun queryInvalidJsonPreservesJsonException () {
128133 // Arrange - mock a 400 response with invalid JSON
129134 val invalidJson = " not valid json at all"
130-
131- webServer.enqueue(MockResponse ()
132- .setResponseCode(400 )
133- .setBody(invalidJson))
135+
136+ webServer.enqueue(
137+ MockResponse ()
138+ .setResponseCode(400 )
139+ .setBody(invalidJson)
140+ )
134141
135142 // Act
136143 val error = Await .error { onResult, onError ->
@@ -142,7 +149,7 @@ class AppSyncErrorPropagationTest {
142149 val cause = error.cause
143150 cause.shouldNotBeNull()
144151 cause.shouldBeInstanceOf<IOException >()
145-
152+
146153 // The IOException should have a JSONException as its cause
147154 val jsonCause = cause.cause
148155 jsonCause.shouldNotBeNull()
0 commit comments