diff --git a/src/activities/Elsa.Activities.Http/Middleware/HttpEndpointMiddleware.cs b/src/activities/Elsa.Activities.Http/Middleware/HttpEndpointMiddleware.cs index b4a33bf7a..f32b1294f 100644 --- a/src/activities/Elsa.Activities.Http/Middleware/HttpEndpointMiddleware.cs +++ b/src/activities/Elsa.Activities.Http/Middleware/HttpEndpointMiddleware.cs @@ -115,6 +115,28 @@ namespace Elsa.Activities.Http.Middleware else { await workflowLaunchpad.ExecutePendingWorkflowAsync(pendingWorkflow, inputModel, cancellationToken); + pendingWorkflowInstance = await workflowInstanceStore.FindByIdAsync(pendingWorkflow.WorkflowInstanceId); + + if (pendingWorkflowInstance is not null + && pendingWorkflowInstance.WorkflowStatus == Elsa.Models.WorkflowStatus.Faulted + && !httpContext.Response.HasStarted) + { + httpContext.Response.ContentType = "application/json"; + httpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError; + + var faultedResponse = JsonConvert.SerializeObject(new + { + errorMessage = $"Workflow faulted at {pendingWorkflowInstance.FaultedAt!} with error: {pendingWorkflowInstance.Fault!.Message}", + workflow = new + { + name = pendingWorkflowInstance.Name, + version = pendingWorkflowInstance.Version, + instanceId = pendingWorkflowInstance.Id + } + }); + + await httpContext.Response.WriteAsync(faultedResponse, cancellationToken); + } } } } diff --git a/src/samples/server/Elsa.Samples.Server.Host/Startup.cs b/src/samples/server/Elsa.Samples.Server.Host/Startup.cs index 83224645b..bf9a1fd7d 100644 --- a/src/samples/server/Elsa.Samples.Server.Host/Startup.cs +++ b/src/samples/server/Elsa.Samples.Server.Host/Startup.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using Elsa.Server.Hangfire.Extensions; using Hangfire; using Microsoft.AspNetCore.Builder;