From a9a0e30192629932e23f98bb853ad782696a819d Mon Sep 17 00:00:00 2001 From: dariuszkuc <9501705+dariuszkuc@users.noreply.github.com> Date: Mon, 3 Jun 2024 17:15:29 -0500 Subject: [PATCH] fix return status code for bad requests --- .../subscription/CallbackWebGraphQLInterceptor.java | 4 +++- .../subscription/CallbackGraphQLHttpHandlerAbstrIT.java | 8 ++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/spring-subscription-callback/src/main/java/com/apollographql/subscription/CallbackWebGraphQLInterceptor.java b/spring-subscription-callback/src/main/java/com/apollographql/subscription/CallbackWebGraphQLInterceptor.java index 0d7bdfaa..d1c1f856 100644 --- a/spring-subscription-callback/src/main/java/com/apollographql/subscription/CallbackWebGraphQLInterceptor.java +++ b/spring-subscription-callback/src/main/java/com/apollographql/subscription/CallbackWebGraphQLInterceptor.java @@ -15,6 +15,8 @@ import org.springframework.graphql.server.WebGraphQlResponse; import org.springframework.graphql.server.WebSocketGraphQlRequest; import org.springframework.graphql.support.DefaultExecutionGraphQlResponse; +import org.springframework.http.HttpStatus; +import org.springframework.web.server.ResponseStatusException; import reactor.core.publisher.Mono; /** @@ -65,7 +67,7 @@ public Mono intercept(WebGraphQlRequest request, Chain chain if (logger.isErrorEnabled()) { logger.error("Unable to start subscription using callback protocol", error); } - return Mono.just(errorCallbackResponse(request)); + return Mono.error(new ResponseStatusException(HttpStatus.BAD_REQUEST)); }); } else { return chain.next(request); diff --git a/spring-subscription-callback/src/test/java/com/apollographql/subscription/CallbackGraphQLHttpHandlerAbstrIT.java b/spring-subscription-callback/src/test/java/com/apollographql/subscription/CallbackGraphQLHttpHandlerAbstrIT.java index 85eaafcd..7c24311a 100644 --- a/spring-subscription-callback/src/test/java/com/apollographql/subscription/CallbackGraphQLHttpHandlerAbstrIT.java +++ b/spring-subscription-callback/src/test/java/com/apollographql/subscription/CallbackGraphQLHttpHandlerAbstrIT.java @@ -99,9 +99,7 @@ public void verifyMalformedCallbackInfo(WebTestClient testClient) { .bodyValue(graphQLRequest) .exchange() .expectStatus() - .is4xxClientError() - .expectBody() - .isEmpty(); + .is4xxClientError(); } public void verifyFailedCallbackInit(WebTestClient testClient) { @@ -116,8 +114,6 @@ public void verifyFailedCallbackInit(WebTestClient testClient) { .bodyValue(graphQLRequest) .exchange() .expectStatus() - .is4xxClientError() - .expectBody() - .isEmpty(); + .is4xxClientError(); } }