-
-
Notifications
You must be signed in to change notification settings - Fork 800
Description
Is your feature request related to a problem?
In the current state of docs, it's unclear how the HTTP status interceptor determines the status code related to exception/returned data value in the resolver.
If you want to implement the 6a pattern and return 200 OK every time a "known" error occurs (for example validation issue), you have to do one of these things:
a) always return nullable! (otherwise, you'll get 500)
b) try-catch the exception -> report exception with resolverCtx.ReportError(...) -> return data/null.
Some people (including myself) don't automatically implement nullable return values, which results in non-sense 500 errors. This behavior of the HotChocolate pipeline should be documented in docs.
Note
This also affects errors related to authentication, if - for example - I return user data that are C# record (non-nullable by nature) and the user isn't authorized, it shoots out 500 HTTP code. When you make the user data record nullable, you get 200 HTTP code. (correct behavior, but this 'authorize' attribute should be namely documented because normally you don't even have to return null in resolver).
The solution you'd like
Add HotChocolate HTTP status code and error behavior in docs.
Product
Hot Chocolate