Skip to content

Commit

Permalink
Renamed "DefaultFaultKinds" to "DefaultFaultTypes" and updated usages
Browse files Browse the repository at this point in the history
This commit renames the class "DefaultFaultKinds" to "DefaultFaultTypes" and updates all its references across the project files. The change is made keeping the more accurate naming context i.e., 'Types' suits better in the thrown exception scenarios.
  • Loading branch information
sfmskywalker committed May 10, 2024
1 parent 7a0adb6 commit 9914ab4
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 18 deletions.
Expand Up @@ -41,7 +41,7 @@ protected override async ValueTask ExecuteAsync(ActivityExecutionContext context
var plan = await manager.GetPlanAsync(planId, cancellationToken);

if (plan == null)
throw new FaultException(AlterationFaultCodes.PlanNotFound, AlterationFaultCategories.Alteration, DefaultFaultKinds.System, $"Alteration Plan with ID {planId} not found.");
throw new FaultException(AlterationFaultCodes.PlanNotFound, AlterationFaultCategories.Alteration, DefaultFaultTypes.System, $"Alteration Plan with ID {planId} not found.");

await manager.CompletePlanAsync(plan, cancellationToken);
}
Expand Down
Expand Up @@ -47,7 +47,7 @@ protected override async ValueTask ExecuteAsync(ActivityExecutionContext context
var plan = await alterationPlanStore.FindAsync(planFilter, cancellationToken);

if (plan == null)
throw new FaultException(AlterationFaultCodes.PlanNotFound, AlterationFaultCategories.Alteration, DefaultFaultKinds.System, $"Alteration Plan with ID {planId} not found.");
throw new FaultException(AlterationFaultCodes.PlanNotFound, AlterationFaultCategories.Alteration, DefaultFaultTypes.System, $"Alteration Plan with ID {planId} not found.");

// Update status.
plan.Status = AlterationPlanStatus.Dispatching;
Expand Down
Expand Up @@ -64,7 +64,7 @@ private async Task<AlterationPlan> GetPlanAsync(ActivityExecutionContext context
var plan = await alterationPlanStore.FindAsync(planFilter, cancellationToken);

if (plan == null)
throw new FaultException(AlterationFaultCodes.PlanNotFound, AlterationFaultCategories.Alteration, DefaultFaultKinds.System, $"Alteration Plan with ID {planId} not found.");
throw new FaultException(AlterationFaultCodes.PlanNotFound, AlterationFaultCategories.Alteration, DefaultFaultTypes.System, $"Alteration Plan with ID {planId} not found.");

return plan;
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Elsa.Http/Activities/WriteFileHttpResponse.cs
Expand Up @@ -303,7 +303,7 @@ private async ValueTask OnResumeAsync(ActivityExecutionContext context)
var httpContext = httpContextAccessor.HttpContext;

if (httpContext == null)
throw new FaultException(HttpFaultCodes.NoHttpContext, HttpFaultCategories.Http, DefaultFaultKinds.System, "Cannot execute in a non-HTTP context");
throw new FaultException(HttpFaultCodes.NoHttpContext, HttpFaultCategories.Http, DefaultFaultTypes.System, "Cannot execute in a non-HTTP context");

await WriteResponseAsync(context, httpContext);
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Elsa.Http/Activities/WriteHttpResponse.cs
Expand Up @@ -86,7 +86,7 @@ private async ValueTask OnResumeAsync(ActivityExecutionContext context)
if (httpContext == null)
{
// We're not in an HTTP context, so let's fail.
throw new FaultException(HttpFaultCodes.NoHttpContext, HttpFaultCategories.Http, DefaultFaultKinds.System, "Cannot execute in a non-HTTP context");
throw new FaultException(HttpFaultCodes.NoHttpContext, HttpFaultCategories.Http, DefaultFaultTypes.System, "Cannot execute in a non-HTTP context");
}

await WriteResponseAsync(context, httpContext.Response);
Expand Down
19 changes: 11 additions & 8 deletions src/modules/Elsa.Workflows.Core/Activities/Fault.cs
Expand Up @@ -23,14 +23,14 @@ public Fault([CallerFilePath] string? source = null, [CallerLineNumber] int? lin
/// <summary>
/// Creates a fault activity.
/// </summary>
public static Fault Create(string code, string category, string kind, string? message = null, [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null)
public static Fault Create(string code, string category, string type, string? message = null, [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null)
{
return new Fault(source, line)
{
Code = new(code),
Message = new(message),
Category = new(category),
Kind = new(kind)
FaultType = new(type)
};
}

Expand All @@ -41,16 +41,19 @@ public static Fault Create(string code, string category, string kind, string? me
public Input<string> Code { get; set; } = default!;

/// <summary>
/// Category to categorize the fault.
/// Category to categorize the fault. Examples: HTTP, Alteration, Azure, etc.
/// </summary>
[Input(Description = "Category to categorize the fault. Examples: HTTP, Alteration, Azure, etc.")]
public Input<string> Category { get; set; } = default!;

/// <summary>
/// The kind of fault.
/// The type of fault. Examples: System, Business, Integration, etc.
/// </summary>
[Input(Description = "The kind of fault. Examples: System, Business, Integration, etc.")]
public Input<string> Kind { get; set; } = default!;
[Input(
DisplayName = "Type",
Description = "The type of fault. Examples: System, Business, Integration, etc."
)]
public Input<string> FaultType { get; set; } = default!;

/// <summary>
/// The message to include with the fault.
Expand All @@ -63,8 +66,8 @@ protected override void Execute(ActivityExecutionContext context)
{
var code = Code.GetOrDefault(context) ?? "0";
var category = Category.GetOrDefault(context) ?? "General";
var kind = Kind.GetOrDefault(context) ?? "System";
var type = FaultType.GetOrDefault(context) ?? "System";
var message = Message.GetOrDefault(context);
throw new FaultException(code, category, kind, message);
throw new FaultException(code, category, type, message);
}
}
@@ -1,6 +1,6 @@
namespace Elsa.Workflows;

public static class DefaultFaultKinds
public static class DefaultFaultTypes
{
public const string System = "System";
public const string Business = "Business";
Expand Down
6 changes: 3 additions & 3 deletions src/modules/Elsa.Workflows.Core/Exceptions/FaultException.cs
Expand Up @@ -6,11 +6,11 @@ namespace Elsa.Workflows.Exceptions;
public class FaultException : Exception
{
/// <inheritdoc />
public FaultException(string code, string category, string kind, string? message) : base(message)
public FaultException(string code, string category, string type, string? message) : base(message)
{
Code = code;
Category = category;
Kind = kind;
Type = type;
}

/// <summary>
Expand All @@ -27,5 +27,5 @@ public FaultException(string code, string category, string kind, string? message
/// <summary>
/// Kind of fault. E.g. "System", "Business", "Integration", etc.
/// </summary>
public string Kind { get; }
public string Type { get; }
}
Expand Up @@ -16,7 +16,7 @@ public record DispatchWorkflowResponse(FaultException? Fault)
/// <summary>
/// Creates a response indicating that the specified channel does not exist.
/// </summary>
public static DispatchWorkflowResponse UnknownChannel() => new(new FaultException(RuntimeFaultCodes.UnknownChannel, RuntimeFaultCategories.Dispatch, DefaultFaultKinds.System, "The specified channel does not exist."));
public static DispatchWorkflowResponse UnknownChannel() => new(new FaultException(RuntimeFaultCodes.UnknownChannel, RuntimeFaultCategories.Dispatch, DefaultFaultTypes.System, "The specified channel does not exist."));

/// <summary>
/// Gets a value indicating whether the dispatch of a workflow definition succeeded.
Expand Down

0 comments on commit 9914ab4

Please sign in to comment.