diff --git a/src/core/Elsa.Abstractions/Models/SimpleException.cs b/src/core/Elsa.Abstractions/Models/SimpleException.cs index 32378a7a7..44c892fc5 100644 --- a/src/core/Elsa.Abstractions/Models/SimpleException.cs +++ b/src/core/Elsa.Abstractions/Models/SimpleException.cs @@ -2,8 +2,21 @@ namespace Elsa.Models { - public record SimpleException(Type Type, string Message, string StackTrace, SimpleException? InnerException = default) + public class SimpleException { + public SimpleException(Type type, string message, string stackTrace, SimpleException? innerException = default) + { + Type = type; + Message = message; + StackTrace = stackTrace; + InnerException = innerException; + } + + public Type Type { get; set; } + public string Message { get; set; } + public string StackTrace { get; set; } + public SimpleException? InnerException { get; set; } + public static SimpleException? FromException(Exception? ex) { if (ex == null) @@ -12,7 +25,7 @@ namespace Elsa.Models var simpleException = new SimpleException(ex.GetType(), ex.Message, ex.StackTrace); if (ex.InnerException != null) - simpleException = simpleException with { InnerException = FromException(ex.InnerException) }; + simpleException.InnerException = FromException(ex.InnerException); return simpleException; } diff --git a/src/core/Elsa.Core/Extensions/ElsaServiceCollectionExtensions.cs b/src/core/Elsa.Core/Extensions/ElsaServiceCollectionExtensions.cs index a6db282bf..a35e13bba 100644 --- a/src/core/Elsa.Core/Extensions/ElsaServiceCollectionExtensions.cs +++ b/src/core/Elsa.Core/Extensions/ElsaServiceCollectionExtensions.cs @@ -212,6 +212,8 @@ namespace Microsoft.Extensions.DependencyInjection services .AddAutoMapperProfile() .AddAutoMapperProfile() + .AddAutoMapperProfile() + .AddTransient() .AddSingleton(); // Caching. diff --git a/src/core/Elsa.Core/Handlers/WriteWorkflowExecutionLog.cs b/src/core/Elsa.Core/Handlers/WriteWorkflowExecutionLog.cs index 23d174655..2abe8b6b5 100644 --- a/src/core/Elsa.Core/Handlers/WriteWorkflowExecutionLog.cs +++ b/src/core/Elsa.Core/Handlers/WriteWorkflowExecutionLog.cs @@ -1,6 +1,8 @@ using System.Threading; using System.Threading.Tasks; +using AutoMapper; using Elsa.Events; +using Elsa.Models; using Elsa.Services; using Elsa.Services.Models; using MediatR; @@ -10,8 +12,14 @@ namespace Elsa.Handlers public class WriteWorkflowExecutionLog : INotificationHandler, INotificationHandler, INotificationHandler { private readonly IWorkflowExecutionLog _workflowExecutionLog; - public WriteWorkflowExecutionLog(IWorkflowExecutionLog workflowExecutionLog) => _workflowExecutionLog = workflowExecutionLog; - + private readonly IMapper _mapper; + + public WriteWorkflowExecutionLog(IWorkflowExecutionLog workflowExecutionLog, IMapper mapper) + { + _workflowExecutionLog = workflowExecutionLog; + _mapper = mapper; + } + public async Task Handle(ActivityExecuting notification, CancellationToken cancellationToken) { var activityExecutionContext = notification.ActivityExecutionContext; @@ -43,11 +51,11 @@ namespace Elsa.Handlers public async Task Handle(ActivityFaulted notification, CancellationToken cancellationToken) { var exception = notification.Exception; + var exceptionModel = _mapper.Map(exception); var data = new { - exception.Message, - exception.StackTrace + exception = exceptionModel }; await WriteEntryAsync("Faulted", exception.Message, notification.ActivityExecutionContext, data, cancellationToken); diff --git a/src/core/Elsa.Core/Mapping/ExceptionConverter.cs b/src/core/Elsa.Core/Mapping/ExceptionConverter.cs new file mode 100644 index 000000000..35bbfb025 --- /dev/null +++ b/src/core/Elsa.Core/Mapping/ExceptionConverter.cs @@ -0,0 +1,28 @@ +using System; +using AutoMapper; +using Elsa.Models; + +namespace Elsa.Mapping +{ + public class ExceptionConverter : ITypeConverter + { + public SimpleException Convert(Exception source, SimpleException? destination, ResolutionContext context) + { + var model = SimpleException.FromException(source)!; + + if (destination != null) + { + destination.Message = model.Message; + destination.Type = model.Type; + destination.StackTrace = model.StackTrace; + destination.InnerException = model.InnerException; + } + else + { + destination = model; + } + + return destination; + } + } +} \ No newline at end of file diff --git a/src/core/Elsa.Core/Mapping/ExceptionProfile.cs b/src/core/Elsa.Core/Mapping/ExceptionProfile.cs new file mode 100644 index 000000000..433cba8f9 --- /dev/null +++ b/src/core/Elsa.Core/Mapping/ExceptionProfile.cs @@ -0,0 +1,14 @@ +using System; +using AutoMapper; +using Elsa.Models; + +namespace Elsa.Mapping +{ + public class ExceptionProfile : Profile + { + public ExceptionProfile() + { + CreateMap().ConvertUsing(); + } + } +} \ No newline at end of file diff --git a/src/designer/elsa-workflows-studio/src/components/screens/workflow-instance-viewer/elsa-workflow-instance-journal/elsa-workflow-instance-journal.tsx b/src/designer/elsa-workflows-studio/src/components/screens/workflow-instance-viewer/elsa-workflow-instance-journal/elsa-workflow-instance-journal.tsx index 38bbf970e..810bf81dd 100644 --- a/src/designer/elsa-workflows-studio/src/components/screens/workflow-instance-viewer/elsa-workflow-instance-journal/elsa-workflow-instance-journal.tsx +++ b/src/designer/elsa-workflows-studio/src/components/screens/workflow-instance-viewer/elsa-workflow-instance-journal/elsa-workflow-instance-journal.tsx @@ -177,7 +177,8 @@ export class ElsaWorkflowInstanceJournal {
-