-
Notifications
You must be signed in to change notification settings - Fork 81
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
Provide a function to write errors to a response from Express/Fastify/Next.js middleware #672
Comments
Hi, @timostamm . I found connect-es is so cool, and I'm willing to help deal with this issue. Is there a CONTRIBUTE Guide or something that introduce me about the code style or what test should be passed? So that I can provide what the community need. Thanks~ |
Hey @CaptainWang98, here is our CONTRIBUTING.md. It has instructions for everything you need to get started 🙂 If you follow the solution described above, you can add tests and run them with |
Thank you for your patience @timostamm , I'm working on this issue now. Since I have less experience in open source community, it may takes me weeks. If I have some questions, I will contact you here~ |
I have had a glance to source code, and I think I should first give out a interface like this: |
@CaptainWang98, defining the function first is a good idea. We are using type ConnectErrorToUniversalResponseFn =
(contentType: string | null, error: ConnectError) => UniversalServerResponse; One suggestion: To make it obvious that the first argument is the request content type, we can name it Other than that, this is a great starting point. You could try to implement the function for the Connect protocol. |
Is your feature request related to a problem? Please describe.
When combining middleware with Connect routes, it is often necessary to return an error to the wire (for example a middleware to authenticate requests).
This is relatively straight-forward for Connect unary. Here is an example for Express with Connect unary:
With streaming, or the other two protocols, it is less straight-forward.
Describe the solution you'd like
To solve this, we can create a function in
@bufbuild/connect/protocol
that takes a request content-type and aConnectError
as arguments, and returns aUniversalServerResponse
with the appropriate headers and body.Then we can export functions specific to server frameworks, that make use of the function we created, but also write the universal response to the server frameworks response object.
Additional context
This feature has some overlap with #527, but would still be useful in many situations as an alternative to server-side interceptors.
The text was updated successfully, but these errors were encountered: