/// <summary> /// Creates a conditional <see cref="EndpointExceptionMappingDelegate"/> which runs /// when exception mapping context meets criteria. /// </summary> /// <param name="innerDelegate">The inner delegate function.</param> public EndpointExceptionMappingDelegate Wrap(EndpointExceptionMappingDelegate innerDelegate) { if (innerDelegate == null) { throw new ArgumentNullException(nameof(innerDelegate)); } if (!HasConditions) { return(innerDelegate); } return((context, httpContext) => { if (!CanHandleException(context, httpContext)) { return Task.CompletedTask; } return innerDelegate(context, httpContext); }); }
/// <summary> /// Creates an instance of the mapping convention. /// </summary> /// <param name="mappingDelegate">Another exception mapping convention.</param> public DelegateExceptionMappingConvention(EndpointExceptionMappingDelegate mappingDelegate) { _mappingDelegate = mappingDelegate ?? throw new ArgumentNullException(nameof(mappingDelegate)); }