Class ValueObjectExceptionInterceptor
Namespace: AdCodicem.ValueObjects.Grpc
Assembly: AdCodicem.ValueObjects.Grpc.dll
Answers a INVALID_ARGUMENT and a
google.rpc.ErrorInfo carrying the rule's code, rather than UNKNOWN.
public sealed class ValueObjectExceptionInterceptor : Interceptor
Inheritance
object ← Interceptor ← ValueObjectExceptionInterceptor
Inherited Members
Interceptor.BlockingUnaryCall<TRequest, TResponse>(TRequest, ClientInterceptorContext<TRequest, TResponse>, Interceptor.BlockingUnaryCallContinuation<TRequest, TResponse>), Interceptor.AsyncUnaryCall<TRequest, TResponse>(TRequest, ClientInterceptorContext<TRequest, TResponse>, Interceptor.AsyncUnaryCallContinuation<TRequest, TResponse>), Interceptor.AsyncServerStreamingCall<TRequest, TResponse>(TRequest, ClientInterceptorContext<TRequest, TResponse>, Interceptor.AsyncServerStreamingCallContinuation<TRequest, TResponse>), Interceptor.AsyncClientStreamingCall<TRequest, TResponse>(ClientInterceptorContext<TRequest, TResponse>, Interceptor.AsyncClientStreamingCallContinuation<TRequest, TResponse>), Interceptor.AsyncDuplexStreamingCall<TRequest, TResponse>(ClientInterceptorContext<TRequest, TResponse>, Interceptor.AsyncDuplexStreamingCallContinuation<TRequest, TResponse>), Interceptor.UnaryServerHandler<TRequest, TResponse>(TRequest, ServerCallContext, UnaryServerMethod<TRequest, TResponse>), Interceptor.ClientStreamingServerHandler<TRequest, TResponse>(IAsyncStreamReader<TRequest>, ServerCallContext, ClientStreamingServerMethod<TRequest, TResponse>), Interceptor.ServerStreamingServerHandler<TRequest, TResponse>(TRequest, IServerStreamWriter<TResponse>, ServerCallContext, ServerStreamingServerMethod<TRequest, TResponse>), Interceptor.DuplexStreamingServerHandler<TRequest, TResponse>(IAsyncStreamReader<TRequest>, IServerStreamWriter<TResponse>, ServerCallContext, DuplexStreamingServerMethod<TRequest, TResponse>), object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()
Remarks
A contract-first service maps the string and int32 fields of its messages to value objects in its
handlers; when the mapping calls Create on a value the value object refuses, Grpc.AspNetCore answers the
exception with UNKNOWN, "Exception was thrown by handler.", and the rule is lost. Registered with
AddGrpc(options => options.Interceptors.Add<ValueObjectExceptionInterceptor>()), or
AddCodeFirstGrpc's for a protobuf-net.Grpc service, this interceptor turns such an exception, one that carries a
code, into an google.rpc.Status holding a
google.rpc.ErrorInfo: its reason is the code mapped by domain the one given, and its metadata holds the code and the valueObject. The status
message is the exception's, which, for one the library throws, names the type and the rule, never the value. A code
that maps to no gRPC reason is answered INVALID_ARGUMENT without the ErrorInfo.
Every other exception goes through as it is, an ValueObjectBinderConfiguration.ForServer of AdCodicem.ValueObjects.ProtobufNet
answers it.
Constructors
ValueObjectExceptionInterceptor(string)
Answers a INVALID_ARGUMENT and a
google.rpc.ErrorInfo carrying the rule's code, rather than UNKNOWN.
public ValueObjectExceptionInterceptor(string domain = "adcodicem.valueobjects")
Parameters
domain string
The google.rpc.ErrorInfo.domain of a refusal, the service's name for instance.
Remarks
A contract-first service maps the string and int32 fields of its messages to value objects in its
handlers; when the mapping calls Create on a value the value object refuses, Grpc.AspNetCore answers the
exception with UNKNOWN, "Exception was thrown by handler.", and the rule is lost. Registered with
AddGrpc(options => options.Interceptors.Add<ValueObjectExceptionInterceptor>()), or
AddCodeFirstGrpc's for a protobuf-net.Grpc service, this interceptor turns such an exception, one that carries a
code, into an google.rpc.Status holding a
google.rpc.ErrorInfo: its reason is the code mapped by domain the one given, and its metadata holds the code and the valueObject. The status
message is the exception's, which, for one the library throws, names the type and the rule, never the value. A code
that maps to no gRPC reason is answered INVALID_ARGUMENT without the ErrorInfo.
Every other exception goes through as it is, an ValueObjectBinderConfiguration.ForServer of AdCodicem.ValueObjects.ProtobufNet
answers it.
Fields
DefaultDomain
The google.rpc.ErrorInfo.domain a refusal is answered with when the application names none.
public const string DefaultDomain = "adcodicem.valueobjects"
Field Value
Methods
ClientStreamingServerHandler<TRequest, TResponse>(IAsyncStreamReader<TRequest>, ServerCallContext, ClientStreamingServerMethod<TRequest, TResponse>)
Server-side handler for intercepting client streaming call.
public override Task<TResponse> ClientStreamingServerHandler<TRequest, TResponse>(IAsyncStreamReader<TRequest> requestStream, ServerCallContext context, ClientStreamingServerMethod<TRequest, TResponse> continuation) where TRequest : class where TResponse : class
Parameters
requestStream IAsyncStreamReader<TRequest>
The request stream of the incoming invocation.
context ServerCallContext
An instance of
continuation ClientStreamingServerMethod<TRequest, TResponse>
A delegate that asynchronously proceeds with the invocation, calling the next interceptor in the chain, or the service request handler, in case of the last interceptor and return the response value of the RPC. The interceptor can choose to call it zero or more times at its discretion.
Returns
Task<TResponse>
A future representing the response value of the RPC. The interceptor can simply return the return value from the continuation intact, or an arbitrary response value as it sees fit. The interceptor has the ability to wrap or substitute the request stream when calling the continuation.
Type Parameters
TRequest
Request message type for this method.
TResponse
Response message type for this method.
DuplexStreamingServerHandler<TRequest, TResponse>(IAsyncStreamReader<TRequest>, IServerStreamWriter<TResponse>, ServerCallContext, DuplexStreamingServerMethod<TRequest, TResponse>)
Server-side handler for intercepting bidirectional streaming calls.
public override Task DuplexStreamingServerHandler<TRequest, TResponse>(IAsyncStreamReader<TRequest> requestStream, IServerStreamWriter<TResponse> responseStream, ServerCallContext context, DuplexStreamingServerMethod<TRequest, TResponse> continuation) where TRequest : class where TResponse : class
Parameters
requestStream IAsyncStreamReader<TRequest>
The request stream of the incoming invocation.
responseStream IServerStreamWriter<TResponse>
The response stream of the incoming invocation.
context ServerCallContext
An instance of
continuation DuplexStreamingServerMethod<TRequest, TResponse>
A delegate that asynchronously proceeds with the invocation, calling the next interceptor in the chain, or the service request handler, in case of the last interceptor and the interceptor can choose to call it zero or more times at its discretion. The interceptor has the ability to wrap or substitute the request and response streams when calling the continuation.
Returns
Type Parameters
TRequest
Request message type for this method.
TResponse
Response message type for this method.
ServerStreamingServerHandler<TRequest, TResponse>(TRequest, IServerStreamWriter<TResponse>, ServerCallContext, ServerStreamingServerMethod<TRequest, TResponse>)
Server-side handler for intercepting server streaming call.
public override Task ServerStreamingServerHandler<TRequest, TResponse>(TRequest request, IServerStreamWriter<TResponse> responseStream, ServerCallContext context, ServerStreamingServerMethod<TRequest, TResponse> continuation) where TRequest : class where TResponse : class
Parameters
request TRequest
The request value of the incoming invocation.
responseStream IServerStreamWriter<TResponse>
The response stream of the incoming invocation.
context ServerCallContext
An instance of
continuation ServerStreamingServerMethod<TRequest, TResponse>
A delegate that asynchronously proceeds with the invocation, calling the next interceptor in the chain, or the service request handler, in case of the last interceptor and the interceptor can choose to call it zero or more times at its discretion. The interceptor has the ability to wrap or substitute the request value and the response stream when calling the continuation.
Returns
Type Parameters
TRequest
Request message type for this method.
TResponse
Response message type for this method.
UnaryServerHandler<TRequest, TResponse>(TRequest, ServerCallContext, UnaryServerMethod<TRequest, TResponse>)
Server-side handler for intercepting an incoming unary call.
public override Task<TResponse> UnaryServerHandler<TRequest, TResponse>(TRequest request, ServerCallContext context, UnaryServerMethod<TRequest, TResponse> continuation) where TRequest : class where TResponse : class
Parameters
request TRequest
The request value of the incoming invocation.
context ServerCallContext
An instance of
continuation UnaryServerMethod<TRequest, TResponse>
A delegate that asynchronously proceeds with the invocation, calling the next interceptor in the chain, or the service request handler, in case of the last interceptor and return the response value of the RPC. The interceptor can choose to call it zero or more times at its discretion.
Returns
Task<TResponse>
A future representing the response value of the RPC. The interceptor can simply return the return value from the continuation intact, or an arbitrary response value as it sees fit.
Type Parameters
TRequest
Request message type for this method.
TResponse
Response message type for this method.