Serialize missing Fault details

This commit is contained in:
Sipke Schoorstra 2023-08-14 14:34:11 +02:00
parent ebd6375f7f
commit 6430d9beec
3 changed files with 10 additions and 8 deletions

View file

@ -3,7 +3,6 @@ using Elsa.EntityFrameworkCore.Modules.Management;
using Elsa.EntityFrameworkCore.Modules.Runtime;
using Elsa.Extensions;
using Elsa.Http.Handlers;
using Elsa.JavaScript.Options;
using Elsa.MongoDb.Extensions;
using Elsa.MongoDb.Modules.Identity;
using Elsa.MongoDb.Modules.Management;
@ -108,6 +107,7 @@ services
});
services.AddHealthChecks();
services.AddControllers();
services.AddCors(cors => cors.AddDefaultPolicy(policy => policy.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().WithExposedHeaders("*")));
// Configure middleware pipeline.

View file

@ -55,7 +55,7 @@ public class EFCoreWorkflowStateStore : IWorkflowStateStore
private async ValueTask OnSaveAsync(RuntimeElsaDbContext dbContext, WorkflowState entity, CancellationToken cancellationToken)
{
var state = new WorkflowStateState(entity.Bookmarks, entity.CompletionCallbacks, entity.ActivityExecutionContexts, entity.Output, entity.Properties);
var state = new WorkflowStateState(entity.Bookmarks, entity.CompletionCallbacks, entity.ActivityExecutionContexts, entity.Output, entity.Properties, entity.Fault);
var json = await _workflowStateSerializer.SerializeAsync(state, cancellationToken);
var now = _systemClock.UtcNow;
var entry = dbContext.Entry(entity);
@ -80,6 +80,7 @@ public class EFCoreWorkflowStateStore : IWorkflowStateStore
entity.ActivityExecutionContexts = data.ActivityExecutionContexts;
entity.Output = data.Output;
entity.Properties = data.Properties;
entity.Fault = data.Fault;
}
private class WorkflowStateState
@ -89,19 +90,19 @@ public class EFCoreWorkflowStateStore : IWorkflowStateStore
{
}
public WorkflowStateState(
ICollection<Bookmark> bookmarks,
public WorkflowStateState(ICollection<Bookmark> bookmarks,
ICollection<CompletionCallbackState> completionCallbacks,
ICollection<ActivityExecutionContextState> activityExecutionContexts,
IDictionary<string, object> output,
IDictionary<string, object> properties
)
IDictionary<string, object> properties,
WorkflowFaultState? fault)
{
Bookmarks = bookmarks;
CompletionCallbacks = completionCallbacks;
ActivityExecutionContexts = activityExecutionContexts;
Output = output;
Properties = properties;
Fault = fault;
}
public ICollection<Bookmark> Bookmarks { get; set; } = new List<Bookmark>();
@ -109,5 +110,6 @@ public class EFCoreWorkflowStateStore : IWorkflowStateStore
public ICollection<ActivityExecutionContextState> ActivityExecutionContexts { get; set; } = new List<ActivityExecutionContextState>();
public IDictionary<string, object> Output { get; set; } = new Dictionary<string, object>();
public IDictionary<string, object> Properties { get; set; } = new Dictionary<string, object>();
public WorkflowFaultState? Fault { get; set; }
}
}

View file

@ -27,14 +27,14 @@ public class DefaultHttpEndpointWorkflowFaultHandler : IHttpEndpointWorkflowFaul
{
var httpContext = context.HttpContext;
var workflowState = context.WorkflowState;
var fault = workflowState.Fault!;
var fault = workflowState.Fault;
httpContext.Response.ContentType = MediaTypeNames.Application.Json;
httpContext.Response.StatusCode = StatusCodes.Status500InternalServerError;
var faultedResponse = _apiSerializer.Serialize(new
{
errorMessage = $"Workflow faulted with error: {fault.Message}",
errorMessage = fault != null ? $"Workflow faulted with error: {fault.Message}" : "Workflow faulted",
workflowState = workflowState
});