elsa-workflows / elsa-workflows/elsa-core
Display Faulted Activity in Journal
- Dominant language
- C#
- Stars
- 7.9k
- Forks
- 1.5k
- Avg merge
- 15h 22m
- Merged PRs (30d)
- 114
Description
Hello @sfmskywalker,
To make custom activity to **Failed ** state in case of any business logic exception, I have implemented the following options in the custom activity exception block:
**Option1:** **throw(ex)** statement
```
try
{
//Business logic
}
catch (Exception ex)
{
_outcome = "Error Occured";
context.JournalData.Add("Exception", ex.Message);
throw (ex);
}
```
If I use the throw statement, I have observed that in the workflow execution instance with fault exception along with fault message and activity state also as "**Faulted**" and also Workflow status as "**Faulted**"


**Option II: Return fault(ex)**
```
try
{
//Business logic
return Done();
}
catch (Exception ex)
{
_outcome = "Error Occured";
context.JournalData.Add("Exception", ex.Message);
return Fault(ex)
}
```
In this case I have observed in the Workflow execution instance as follow: Activity state is "**Executed**" and Workflow status as "**Faulted**"
"

**Option -III:** Implemented **WorkflowFault** method.
```
try
{
//Business logic
}
catch (Exception ex)
{
_outcome = "Error Occured";
context.JournalData.Add("Exception", ex.Message);
context.WorkflowInstance.Fault = new Elsa.Models.WorkflowFault(null, "Exception occured at activity level", context.ActivityId.ToString(), context.Input, context.Resuming);
}
```
In this case Workflow status is "**Finished**" and Activity Status is "**Executed**"



So Please suggest the best practice/ approach to use the activity failed state using above approach.
Also, if any alternative better idea please suggest as well for the same.
_Originally posted by @jayachandra21 in https://github.com/elsa-workflows/elsa-core/discussions/2687_
Contributor guide
Assessment
This issue has not been assessed yet.