/// <summary> /// If current call is cancelled invokes OnOperationCancelled, otherwise invokes ProvideFaultOrIgnoreCore. /// </summary> /// <param name="context">The context associated with the current call.</param> /// <param name="error">The <see cref="Exception"/> object thrown in the course of the service operation.</param> /// <returns>Result of ProvideFaultOrIgnoreCore if operation is not cancelled, otherwise null.</returns> public virtual ServerFaultDetail?ProvideFaultOrIgnore(ServerCallInterceptorContext context, Exception error) { // call is already aborted by client, no reason to provide details if (IsOperationCancelled(context.ServerCallContext, error)) { OnOperationCancelled(context, error); return(null); } return(ProvideFaultOrIgnoreCore(context, error)); }
/// <summary> /// Invokes ProvideFaultOrIgnore of handlers in the pipeline ony by one until the result is not null. /// </summary> /// <param name="context">The context associated with the current call.</param> /// <param name="error">The <see cref="Exception"/> object thrown in the course of the service operation.</param> /// <returns>The first non null result provided by a handler in the pipeline, otherwise null.</returns> protected override ServerFaultDetail?ProvideFaultOrIgnoreCore(ServerCallInterceptorContext context, Exception error) { for (var i = 0; i < _pipeline.Count; i++) { var errorHandler = _pipeline[i]; var detail = errorHandler.ProvideFaultOrIgnore(context, error); if (detail.HasValue) { return(detail); } } return(null); }
public void BeforeEachTest() { _sut = new Mock <ServerErrorHandlerBase> { CallBase = true }; _tokenSource = new CancellationTokenSource(); _rpcContext = new Mock <ServerCallContext>(MockBehavior.Strict); _rpcContext .Protected() .SetupGet <CancellationToken>("CancellationTokenCore") .Returns(_tokenSource.Token); _errorContext = new ServerCallInterceptorContext(_rpcContext.Object); }
/// <summary> /// Allows to provide external detail to a client call. /// </summary> /// <param name="context">The context associated with the current call.</param> /// <param name="error">The <see cref="Exception"/> object thrown in the course of the service operation.</param> /// <returns>Optional error detail that is returned to the client.</returns> protected abstract ServerFaultDetail?ProvideFaultOrIgnoreCore(ServerCallInterceptorContext context, Exception error);
/// <summary> /// Enables custom action when call is cancelled. /// Call is already aborted by a client, no reason to provide details. /// </summary> /// <param name="context">The context associated with the current call.</param> /// <param name="error">The <see cref="Exception"/> object thrown in the course of the service operation.</param> protected virtual void OnOperationCancelled(ServerCallInterceptorContext context, Exception error) { }