spring-projects / spring-graphql

Spring Integration for GraphQL
https://spring.io/projects/spring-graphql
Apache License 2.0
1.53k stars 306 forks source link

Ensure all Publisher errors are handled consistently in SSE handlers #1080

Closed rstoyanchev closed 1 month ago

rstoyanchev commented 1 month ago

The review of error handling under #1067 uncovered an inconsistency in error handling. If the exception coming from the Publisherside is a SubscriptionPublisherException, it is written as a GraphQL spec map with an "error" section, followed by a "complete" message. This help the client understand the stream was ended intentionally and to provide a reason. For any other error, however, we simply close the SSE stream without writing anything.

In most cases we do expect SubscriptionPublisherException as a result of an annotated exception handler or a SubscriptionExceptionResolver have resolved it to GraphQL errors. However, in the unlikely event that it wasn't resolved at all, we still need to create a default GraphQL error, and write that before sending "complete".