diff --git a/src/modules/Elsa.Workflows.Core/Middleware/Workflows/EngineExceptionHandlingMiddleware.cs b/src/modules/Elsa.Workflows.Core/Middleware/Workflows/EngineExceptionHandlingMiddleware.cs index 3cc30025a..0987b567c 100644 --- a/src/modules/Elsa.Workflows.Core/Middleware/Workflows/EngineExceptionHandlingMiddleware.cs +++ b/src/modules/Elsa.Workflows.Core/Middleware/Workflows/EngineExceptionHandlingMiddleware.cs @@ -7,48 +7,28 @@ using Microsoft.Extensions.Logging; namespace Elsa.Workflows.Middleware.Workflows; -/// /// Adds extension methods to . -/// public static class EngineExceptionHandlingMiddlewareExtensions { - /// /// Installs the component in the activity execution pipeline. - /// public static IWorkflowExecutionPipelineBuilder UseEngineExceptionHandling(this IWorkflowExecutionPipelineBuilder pipelineBuilder) => pipelineBuilder.UseMiddleware(); } -/// /// Catches any exceptions thrown by downstream components and transitions the workflow into the faulted state. -/// -public class EngineExceptionHandlingMiddleware : IWorkflowExecutionMiddleware +public class EngineExceptionHandlingMiddleware(WorkflowMiddlewareDelegate next, ISystemClock systemClock, ILogger logger) : IWorkflowExecutionMiddleware { - private readonly WorkflowMiddlewareDelegate _next; - private readonly ISystemClock _systemClock; - private readonly ILogger _logger; - - /// - /// Constructor. - /// - public EngineExceptionHandlingMiddleware(WorkflowMiddlewareDelegate next, ISystemClock systemClock, ILogger logger) - { - _next = next; - _systemClock = systemClock; - _logger = logger; - } - /// public async ValueTask InvokeAsync(WorkflowExecutionContext context) { try { - await _next(context); + await next(context); } catch (Exception e) { - _logger.LogWarning(e, "An exception was caught from a downstream middleware component"); + logger.LogWarning(e, "An exception was caught from a downstream middleware component"); var exceptionState = ExceptionState.FromException(e); - var now = _systemClock.UtcNow; + var now = systemClock.UtcNow; var activity = context.Workflow; var incident = new ActivityIncident(activity.Id, activity.Type, e.Message, exceptionState, now);