3131import org .springframework .graphql .execution .SubscriptionPublisherException ;
3232import org .springframework .graphql .server .WebGraphQlHandler ;
3333import org .springframework .graphql .server .WebGraphQlResponse ;
34- import org .springframework .util .AlternativeJdkIdGenerator ;
35- import org .springframework .util .IdGenerator ;
3634import org .springframework .web .context .request .async .AsyncRequestTimeoutException ;
3735import org .springframework .web .servlet .function .ServerRequest ;
3836import org .springframework .web .servlet .function .ServerResponse ;
4947 */
5048public class GraphQlSseHandler extends AbstractGraphQlHttpHandler {
5149
52- private final IdGenerator idGenerator = new AlternativeJdkIdGenerator ();
53-
54-
5550 public GraphQlSseHandler (WebGraphQlHandler graphQlHandler ) {
5651 super (graphQlHandler , null );
5752 }
@@ -94,12 +89,7 @@ private static final class SseSubscriber extends BaseSubscriber<Map<String, Obje
9489
9590 private SseSubscriber (ServerResponse .SseBuilder sseBuilder ) {
9691 this .sseBuilder = sseBuilder ;
97- this .sseBuilder .onTimeout (this ::onTimeout );
98- }
99-
100- private void onTimeout () {
101- this .cancel ();
102- this .sseBuilder .error (new AsyncRequestTimeoutException ());
92+ this .sseBuilder .onTimeout (() -> cancelWithError (new AsyncRequestTimeoutException ()));
10393 }
10494
10595 @ Override
@@ -113,11 +103,15 @@ private void writeResult(Map<String, Object> value) {
113103 this .sseBuilder .data (value );
114104 }
115105 catch (IOException exception ) {
116- cancel ();
117- hookOnError (exception );
106+ cancelWithError (exception );
118107 }
119108 }
120109
110+ private void cancelWithError (Throwable ex ) {
111+ this .cancel ();
112+ this .sseBuilder .error (ex );
113+ }
114+
121115 @ Override
122116 protected void hookOnError (Throwable ex ) {
123117 if (ex instanceof SubscriptionPublisherException spe ) {
0 commit comments