< Summary

Information
Class: Elsa.Workflows.Middleware.Activities.ExceptionHandlingMiddleware
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Middleware/Activities/ExceptionHandlingMiddleware.cs
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 44
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
InvokeAsync()100%11100%
HandleIncidentAsync()100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Middleware/Activities/ExceptionHandlingMiddleware.cs

#LineLine coverage
 1using Elsa.Extensions;
 2using Elsa.Workflows.Pipelines.ActivityExecution;
 3using Microsoft.Extensions.Logging;
 4
 5namespace Elsa.Workflows.Middleware.Activities;
 6
 7/// <summary>
 8/// Adds extension methods to <see cref="ExceptionHandlingMiddleware"/>.
 9/// </summary>
 10public static class ExceptionHandlingMiddlewareExtensions
 11{
 12    /// <summary>
 13    /// Installs the <see cref="ExceptionHandlingMiddleware"/> component in the activity execution pipeline.
 14    /// </summary>
 15    public static IActivityExecutionPipelineBuilder UseExceptionHandling(this IActivityExecutionPipelineBuilder pipeline
 16}
 17
 18/// <summary>
 19/// Catches any exceptions thrown by downstream components and transitions the workflow into the faulted state.
 20/// </summary>
 42121public class ExceptionHandlingMiddleware(ActivityMiddlewareDelegate next, IIncidentStrategyResolver incidentStrategyReso
 22    : IActivityExecutionMiddleware
 23{
 24    /// <inheritdoc />
 25    public async ValueTask InvokeAsync(ActivityExecutionContext context)
 26    {
 27        try
 28        {
 301929            await next(context);
 300630        }
 1331        catch (Exception e)
 32        {
 1333            logger.LogWarning(e, "An exception was caught from a downstream middleware component");
 1334            context.Fault(e);
 1335            await HandleIncidentAsync(context);
 36        }
 301937    }
 38
 39    private async Task HandleIncidentAsync(ActivityExecutionContext context)
 40    {
 1341        var strategy = await incidentStrategyResolver.ResolveStrategyAsync(context);
 1342        strategy.HandleIncident(context);
 1343    }
 44}