-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
Server side: Exception handling middleware / Interceptors #22
Comments
Are you talking about something that already exists in the main gRPC library, that I'm not exposing - or are you talking about something bespoke and new? For the first: indeed I haven't done anything extra there; show me the API and I'll consider it For the second: what would you propose? |
You'll likely want to expose it in your AddCodeFirstGrpc ext method: public static void AddCodeFirstGrpc(this IServiceCollection services, Action<GrpcServiceOptions> configureOptions=null)
{
services.AddGrpc(configureOptions);
services.TryAddEnumerable(ServiceDescriptor.Singleton(typeof(IServiceMethodProvider<>), typeof(CodeFirstServiceMethodProvider<>)));
} So it can be added like: services.AddCodeFirstGrpc(options => options.Interceptors.Add<MyInterceptor>()); |
Yeah, It will be very good to wide AddCodeFirstGrpc with "configureOptions", but it's not critical.
But I have no idea how to add interceptors via And in general, interceptors cannot be configured to catch exceptions which are generated by a code. The main idea is connected with the DRY principle - I don't want to repeat try-catch blocks in all grpc calls, but I want to realize it once. It could be realized on the server side by wrapping in try-catch Maybe, do you know the way to add ASP,NET Core exception handling (have a code examples - it's an offtop)? And also it could be great to add mechanism of interceptors adding on the client side. Thank you. |
Potentially, It could be added here (interceptors for the grpc client) in the
You could rewrite it like:
or
I'll try to run this code to check what's better to use. |
1.0.13 added an overload that allows this configuration at the server, both on the input and the return I think that covers everything here, so I'm marking it as completed by 18ef9be - if I'm wrong, ping me and we can reopen. |
Marc, I think, you also should add interceptors on the client side. Earlier I wrote the code examples which could be used:
or
On the server side |
@GoNextGroup k; let's consider this (#22) "server-side", and we'll take the client-side conversation to #26 |
Hello.
Is it possible to add here any mechanism to realize interceptors and exceptions handling on the client and server side?
Thank you.
The text was updated successfully, but these errors were encountered: