Skip to content
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

Feature request - Ability to write errors to huma.Context during a StreamResponse #574

Open
ddl-ebrown opened this issue Sep 17, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@ddl-ebrown
Copy link
Contributor

When implementing a streaming API, there are some instances where processing may fail inside of the Body function, that could be returned as errors.

I understand that making the signature Body: func(ctx huma.Context) (error) instead of Body: func(ctx huma.Context) doesn't make much sense, because once streaming starts returning an error is not possible.

However, before streaming starts it's still possible to return / serialize a JSON error. Doing that requires a bit of boilerplate to set the status header / serialize the response to JSON. I think it would be useful to be able to have helpers that can take a huma.StatusError and write it out to the response through huma.Context. I'm thinking something along the lines of huma.WriteErr, but easier to use. Having access to an api instance in this scenario doesn't feel like the right design / usage.

Thoughts?

@danielgtaylor danielgtaylor added the enhancement New feature or request label Oct 8, 2024
@danielgtaylor
Copy link
Owner

@ddl-ebrown that's a great idea. I do think needing the API instance makes sense though, because content negotiation and marshaling happen from the formats registered with the API instance. Open to ideas how best to implement this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants