Skip to content

Commit 9fcaef7

Browse files
authored
spring-server: include path in SimpleKotlinGraphQLError default error message (#392)
1 parent 3714f22 commit 9fcaef7

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

graphql-kotlin-spring-server/src/main/kotlin/com/expediagroup/graphql/spring/exception/SimpleKotlinGraphQLError.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ open class SimpleKotlinGraphQLError(
4242

4343
override fun getLocations(): List<SourceLocation> = locations
4444

45-
override fun getMessage(): String = exception.message ?: "Exception was thrown while executing a GraphQL query"
45+
override fun getMessage(): String = "Exception while fetching data (${path?.joinToString("/").orEmpty()}) : ${exception.message}"
4646

4747
override fun getPath(): List<Any>? = path
4848
}

graphql-kotlin-spring-server/src/test/kotlin/com/expediagroup/graphql/spring/exception/SimpleKotlinGraphQLErrorTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ internal class SimpleKotlinGraphQLErrorTest {
4545

4646
@Test
4747
fun `Message comes from the exception if set`() {
48-
val error = SimpleKotlinGraphQLError(Throwable("foo"))
49-
assertEquals(expected = "foo", actual = error.message)
48+
val error = SimpleKotlinGraphQLError(exception = Throwable("foo"), path = listOf("/foo"))
49+
assertEquals(expected = "Exception while fetching data (/foo) : foo", actual = error.message)
5050
}
5151

5252
@Test

graphql-kotlin-spring-server/src/test/kotlin/com/expediagroup/graphql/spring/execution/QueryHandlerTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class QueryHandlerTest {
141141
val error = errors.first()
142142
assertTrue(error is SimpleKotlinGraphQLError)
143143
assertEquals(ErrorType.DataFetchingException, error.errorType)
144-
assertEquals("Uncaught JUNIT", error.message)
144+
assertEquals("Exception while fetching data () : Uncaught JUNIT", error.message)
145145
}
146146
assertNull(response.extensions)
147147
}

graphql-kotlin-spring-server/src/test/kotlin/com/expediagroup/graphql/spring/execution/SubscriptionHandlerTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class SubscriptionHandlerTest {
9696
assertNotNull(response.errors) { errors ->
9797
assertEquals(1, errors.size)
9898
val error = errors.first()
99-
assertEquals("JUNIT subscription failure", error.message)
99+
assertEquals("Exception while fetching data () : JUNIT subscription failure", error.message)
100100
assertEquals(ErrorType.DataFetchingException, error.errorType)
101101
}
102102
assertNull(response.extensions)

0 commit comments

Comments
 (0)