Skip to content

Commit

Permalink
Merge pull request #2069 from Netflix/fix/2059
Browse files Browse the repository at this point in the history
Remove incorrect toString() for URL in RestClientGraphQLClient error handling
  • Loading branch information
paulbakker authored Nov 22, 2024
2 parents f112648 + 5d3990a commit 0df18d0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class RestClientGraphQLClient(
if (!responseEntity.statusCode.is2xxSuccessful) {
throw GraphQLClientException(
statusCode = responseEntity.statusCode.value(),
url = restClient.toString(),
url = "",
response = responseEntity.body ?: "",
request = serializedRequest,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import graphql.schema.idl.RuntimeWiring
import graphql.schema.idl.SchemaParser
import graphql.schema.idl.TypeDefinitionRegistry
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatException
import org.intellij.lang.annotations.Language
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand All @@ -45,6 +46,7 @@ import org.springframework.boot.test.web.server.LocalServerPort
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
import org.springframework.web.bind.annotation.RequestHeader
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.client.HttpClientErrorException
import org.springframework.web.client.RestClient
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
Expand Down Expand Up @@ -82,6 +84,27 @@ class RestClientGraphQLClientTest {
assertThat(result).isEqualTo("Hi!")
}

@Test
fun `Unsuccessful request with default status handling`() {
val client = RestClientGraphQLClient(restClient.mutate().baseUrl("http://localhost:$port/wrongpath").build())
assertThatException().isThrownBy { client.executeQuery("{hello}") }.isInstanceOf(HttpClientErrorException::class.java)
}

@Test
fun `Unsuccessful request with non default status handling`() {
val client =
RestClientGraphQLClient(
restClient
.mutate()
.defaultStatusHandler(
{ true },
{ _, _ -> },
).baseUrl("http://localhost:$port/wrongpath")
.build(),
)
assertThatException().isThrownBy { client.executeQuery("{hello}") }.isInstanceOf(GraphQLClientException::class.java)
}

@Test
fun `Extra header can be provided`() {
val client =
Expand Down

0 comments on commit 0df18d0

Please sign in to comment.