-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add method for custom formatting of stream errors. #564
Add method for custom formatting of stream errors. #564
Conversation
I would much prefer the handler's signature to be more in the style of (Default)HTTPError, so that a client can write the stream error however they wish. In my case, I would like to construct my own error status proto directly and avoid my marshalers having to handle maps. |
Could you come up with a practical alternative? The stream is already established at this point, so a handler function may require rewriting of much of the logic. |
@abursavich Thanks for that! I think one problem with your approach is that we expose a new function type, used by the user, which has an empty interface in the signature. That's pretty poor interface design. It also rewrites quite a bit of the logic, and it seems to add an error case if the response is nil, which may break backwards compatibility? I think your suggestion is a step in the right direction, as I would also like more control over the writing of mesages, but maybe the configuration should be more fine grained? One option for formatting the error and one for formatting a successful reply? I'm not sure. |
FWIW, the error on nil response was already there, I just lifted it out of streamChunk (which I deleted): grpc-gateway/runtime/handler.go Lines 185 to 187 in cde2f8f
I don't like the empty interface much either, but I was matching the existing interface for Marshaler: grpc-gateway/runtime/marshaler.go Lines 7 to 20 in e4b8a93
|
My heart is not really in this change after merging #561, so I will close this to let someone else provide a better solution to the specific problem of customizing stream error returns. |
Alternative to discussion in #538 (comment). This would allow a user to get errors as marshalled
status.Proto()
types with the use of bothWithProtoStreamErrorFormatter
andWithProtoErrorHandler
.This is pretty experimental so I'm happy to make any changes.