Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove incorrect toString() for URL in RestClientGraphQLClient error handling #2069

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading