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

Right way to handle errors. #11

Closed
humb1t opened this issue Mar 20, 2024 · 7 comments
Closed

Right way to handle errors. #11

humb1t opened this issue Mar 20, 2024 · 7 comments

Comments

@humb1t
Copy link

humb1t commented Mar 20, 2024

Hello, thanks a lot for this interesting project for gRPC support in Rust ecosystem.
I'm working on a replacing of tonic with ntex-grpc. One thing that I'm struggling with at the moment is error handling.
What is the ntex-grpc way to handle errors in server?

    #[method(VerifyCredentials)]
    async fn verify_credentials(
        &self,
        VerifyCredentialsRequest { token }: VerifyCredentialsRequest,
    ) -> Result<VerifyCredentialsResponse> {

My idea was to use Result in method definition, but maybe idea in ntex-grpc is to write possible error structures in proto file and use oneof with success/fail structures for response types?

@fafhrd91
Copy link
Member

at the moment error handling in server side is not very detailed, you have to return proto response.

if you really want to use ntex-grpc, you have to be prepared to dig in internals. i didnt work on server side api much, it is need more work in term of usability

@fafhrd91
Copy link
Member

if you willing to spend time on server side api, i can help. personally, i wont be able to spend much time in near term

@humb1t
Copy link
Author

humb1t commented Mar 21, 2024

@fafhrd91 thanks a lot. I can contribute and interested in it. Can you please help with defining your ideas or thoughts on it and I will try to implement them.

@fafhrd91
Copy link
Member

fafhrd91 commented Mar 21, 2024

quick idea is to use Responder style trait, similar to actix-web or ntex.

method call would be something like:

async fn method(&self, req: proto::Request) -> impl Responder<proto::Response>;

then it would be possible to define Responder like:

impl<T, E> Responder<Result<T, E>> for proto::Response 
where
   T: Into<proto::Response>
   E: Into<proto::Response>
{
}

also Into could be replaced with TryInto, so failed conversion could be treated as grpc level error

@fafhrd91
Copy link
Member

this is just an idea, feel free to design something more interesting

@humb1t
Copy link
Author

humb1t commented Mar 21, 2024

I think it's a good idea. I will start working on it late March, early April.

@fafhrd91
Copy link
Member

fafhrd91 commented Dec 9, 2024

added simple response error handling Result<Method::Output, impl IntoMethod::Output>

@fafhrd91 fafhrd91 closed this as completed Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants