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

feat(volo-http): use generic types for resp and err #361

Merged
merged 2 commits into from
Feb 18, 2024

Conversation

yukiiiteru
Copy link
Member

Motivation

The previous code uses a fixed Service with Response = ServerResponse and Error = Infallible, which is not flexible enough.

Solution

This PR updates Services for server. Its Response can be of any type with IntoResponse, and Error can be any type without trait. The only restriction is that the Error must be converted to ServerResponse (with Error = Infallible) before it is given to the client.

In other words, you can define your own error code in the business code, but you must handle it before sending it to client.

An example is also updated where you can create a service with an error code (usize in the example, which doesn't implement IntoResponse) and wrap it with a layer to convert it.

Signed-off-by: Yu Li <liyu.yukiteru@bytedance.com>
Signed-off-by: Yu Li <liyu.yukiteru@bytedance.com>
@yukiiiteru yukiiiteru requested review from a team as code owners February 18, 2024 08:51
@yukiiiteru yukiiiteru mentioned this pull request Feb 18, 2024
15 tasks
@yukiiiteru yukiiiteru merged commit f468e3f into cloudwego:main Feb 18, 2024
13 checks passed
@yukiiiteru yukiiiteru deleted the feat/any-response-and-err branch February 18, 2024 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants