Improve error messages

Closes #1425
This commit is contained in:
Sipke Schoorstra 2021-08-31 16:09:04 +02:00
parent 64ec9dade7
commit fc954d9968
5 changed files with 51 additions and 5 deletions

View file

@ -128,7 +128,7 @@ namespace Elsa.Activities.Http.Middleware
pendingWorkflowInstance = await workflowInstanceStore.FindByIdAsync(pendingWorkflow.WorkflowInstanceId, cancellationToken);
if (pendingWorkflowInstance is not null
&& pendingWorkflowInstance.WorkflowStatus == Elsa.Models.WorkflowStatus.Faulted
&& pendingWorkflowInstance.WorkflowStatus == WorkflowStatus.Faulted
&& !httpContext.Response.HasStarted)
{
httpContext.Response.ContentType = "application/json";
@ -137,6 +137,7 @@ namespace Elsa.Activities.Http.Middleware
var faultedResponse = JsonConvert.SerializeObject(new
{
errorMessage = $"Workflow faulted at {pendingWorkflowInstance.FaultedAt!} with error: {pendingWorkflowInstance.Fault!.Message}",
exception = pendingWorkflowInstance.Fault?.Exception,
workflow = new
{
name = pendingWorkflowInstance.Name,

View file

@ -1,28 +1,33 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace Elsa.Models
{
public class SimpleException
{
public SimpleException(Type type, string message, string stackTrace, SimpleException? innerException = default)
public SimpleException(Type type, string message, string stackTrace, IDictionary data, SimpleException? innerException = default)
{
Type = type;
Message = message;
StackTrace = stackTrace;
InnerException = innerException;
Data = data;
}
public Type Type { get; set; }
public string Message { get; set; }
public string StackTrace { get; set; }
public SimpleException? InnerException { get; set; }
public IDictionary Data { get; set; }
public static SimpleException? FromException(Exception? ex)
{
if (ex == null)
return null;
var simpleException = new SimpleException(ex.GetType(), ex.Message, ex.StackTrace);
var exceptionType = ex.GetType();
var simpleException = new SimpleException(exceptionType, ex.Message, ex.StackTrace, ex.Data);
if (ex.InnerException != null)
simpleException.InnerException = FromException(ex.InnerException);

View file

@ -0,0 +1,14 @@
namespace Elsa.Models
{
public class SimpleExceptionProperty
{
public SimpleExceptionProperty(string name, object value)
{
Name = name;
Value = value;
}
public string Name { get; set; }
public object Value { get; set; }
}
}

View file

@ -0,0 +1,25 @@
using System;
namespace Elsa.Exceptions
{
public class ExpressionEvaluationException : Exception
{
public string Expression
{
get => (string)Data[nameof(Expression)];
set => Data[nameof(Expression)] = value;
}
public string Syntax
{
get => (string)Data[nameof(Syntax)];
set => Data[nameof(Syntax)] = value;
}
public ExpressionEvaluationException(string message, string expression, string syntax, Exception innerException) : base(message, innerException)
{
Expression = expression;
Syntax = syntax;
}
}
}

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Elsa.Exceptions;
using Elsa.Models;
using Elsa.Services.Models;
using Microsoft.Extensions.Logging;
@ -63,7 +64,7 @@ namespace Elsa.Expressions
catch (Exception e)
{
_logger.LogDebug(e, "Failed to evaluate expression {Expression} using syntax {Syntax}", expression, syntax);
throw;
throw new ExpressionEvaluationException("Failed to evaluate expression", expression, syntax, e);
}
}
}