private IErrorHandling _errorHandling = new FileLogger(); // BAD public void Add() { try { // Adding logic } catch (Exception ex) { _errorHandling.Handle(ex.Message); } }
public override async Task InvokeAsync(ClientActionContext context) { try { await Next(context).ConfigureAwait(false); } catch (Exception e) { ErrorHandlingResult result = _errorHandling.Handle(context, e); if (result == ErrorHandlingResult.Close || result == ErrorHandlingResult.Recover) { (context.Proxy as IPipelineCallback)?.ChangeState(ProxyState.Closed); } throw; } }