spring-graphql icon indicating copy to clipboard operation
spring-graphql copied to clipboard

Methods that access the resopnse should raise GraphQlException consistently

Open GeorgEchterling opened this issue 8 months ago • 1 comments

When calling ClientResponseField.toEntity(someClass) on a field that cannot be deserialized into the given type, the method will throw an HttpMessageNotReadableException.

Spring MVC's ResponseEntityExceptionHandler will unfortunately convert this into a 400 Bad Request response, while this error should actually be treated as an internal server error. (The error was caused because the GraphQL response could not be read.)

It would be nice if ClientResponseField.toEntity could wrap this exception in a way that distinguishes it from actual client errors.

Spring GraphQL version: 1.4.0

GeorgEchterling avatar May 27 '25 06:05 GeorgEchterling

That makes sense. Methods to access the response already throw FieldAccessExceptions, an extension of GraphQlClientException. We could wrap any others as GraphQlClientException similar to what RestClient does for such errors.

rstoyanchev avatar May 29 '25 11:05 rstoyanchev