2022-03-09 23:19:00 +00:00
|
|
|
using System.Net.Mime;
|
|
|
|
|
using System.Text.Json;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Http.Models;
|
|
|
|
|
using Elsa.Http.Services;
|
2022-03-09 23:19:00 +00:00
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
2022-05-26 10:47:31 +00:00
|
|
|
namespace Elsa.Http.Handlers;
|
2022-03-09 23:19:00 +00:00
|
|
|
|
2022-04-27 20:32:40 +00:00
|
|
|
// ReSharper disable once ClassWithVirtualMembersNeverInherited.Global
|
2022-03-09 23:19:00 +00:00
|
|
|
public class DefaultHttpEndpointWorkflowFaultHandler : IHttpEndpointWorkflowFaultHandler
|
|
|
|
|
{
|
|
|
|
|
public virtual async ValueTask HandleAsync(HttpEndpointFaultedWorkflowContext context)
|
|
|
|
|
{
|
|
|
|
|
var httpContext = context.HttpContext;
|
|
|
|
|
var workflowInstance = context.WorkflowInstance;
|
|
|
|
|
|
|
|
|
|
httpContext.Response.ContentType = MediaTypeNames.Application.Json;
|
|
|
|
|
httpContext.Response.StatusCode = StatusCodes.Status500InternalServerError;
|
|
|
|
|
|
|
|
|
|
var faultedResponse = JsonSerializer.Serialize(new
|
|
|
|
|
{
|
|
|
|
|
errorMessage = $"Workflow faulted at {workflowInstance.FaultedAt!} with error: {workflowInstance.Fault!.Message}",
|
|
|
|
|
exception = workflowInstance.Fault?.Exception,
|
|
|
|
|
workflow = new
|
|
|
|
|
{
|
|
|
|
|
name = workflowInstance.Name,
|
|
|
|
|
version = workflowInstance.Version,
|
|
|
|
|
instanceId = workflowInstance.Id
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await httpContext.Response.WriteAsync(faultedResponse, context.CancellationToken);
|
|
|
|
|
}
|
|
|
|
|
}
|