Skip to content

Commit

Permalink
feat(dotnet-sdk): add LH business exception in Task Worker
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlaCarvajal committed Nov 25, 2024
1 parent f4abe43 commit 39eeea6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
21 changes: 21 additions & 0 deletions sdk-dotnet/LittleHorse.Sdk/Exceptions/LHTaskException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using LittleHorse.Common.Proto;

namespace LittleHorse.Sdk.Exceptions;

public class LHTaskException: Exception
{
private String name;
private VariableValue content;

public LHTaskException(String name, String message): base(message)
{
this.name = name;
this.content = null;
}

public LHTaskException(String name, String message, VariableValue content): base(message)
{
this.name = name;
this.content = content;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Extensions.Logging;
using Polly;
using static LittleHorse.Common.Proto.LittleHorse;
using LHTaskException = LittleHorse.Sdk.Exceptions.LHTaskException;
using TaskStatus = LittleHorse.Common.Proto.TaskStatus;

namespace LittleHorse.Sdk.Worker.Internal
Expand Down Expand Up @@ -225,6 +226,15 @@ private ReportTaskRun ExecuteTask(ScheduledTask scheduledTask, DateTime? schedul
taskResult.LogOutput = LHMappingHelper.MapExceptionToVariableValue(ex, workerContext);
taskResult.Status = TaskStatus.TaskOutputSerializingError;
}
catch (TargetInvocationException ex)
{
if (ex is LHTaskException)
{
_logger?.LogError(ex, "Task Method threw a Business Exception");
taskResult.LogOutput = LHMappingHelper.MapExceptionToVariableValue(ex, workerContext);
taskResult.Status = TaskStatus.TaskException;
}
}
catch (Exception ex)
{
_logger?.LogError(ex, "Unexpected exception during task execution");
Expand Down

0 comments on commit 39eeea6

Please sign in to comment.