Refactor JobException message handling

Renamed the `Message` method to `CreateMessage` for clarity and updated its usage in the `JobException` constructor. Simplified the error message format by removing visual separator lines, resulting in cleaner and more concise output.
This commit is contained in:
2026-08-03 10:34:35 +02:00
parent af3c8be133
commit 2d7c54ceae

View File

@@ -26,7 +26,7 @@ namespace ECMJobRunner.Application.Common.Exceptions
/// </remarks>
public JobException(string jobName, string processName, string batchId, string? reason, Exception? innerException, params (string Name, string? Value, bool IgnoreIfNull)[] details)
: base(
Message(jobName,
CreateMessage(jobName,
[
("Process Name", processName, false),
("Batch Id", batchId, false),
@@ -65,26 +65,22 @@ namespace ECMJobRunner.Application.Common.Exceptions
/// Message format:
/// <code>
/// {jobName} could not be completed.
/// ─────────────────────────────────────────
/// Process Name: {processName}
/// Batch Id: {batchId}
/// {additional details...}
/// ─────────────────────────────────────────
/// </code>
/// Details with IgnoreIfNull=true are omitted when their value is null.
/// </remarks>
internal static string Message(string jobName, IEnumerable<(string Name, string? Value, bool IgnoreIfNull)> details)
internal static string CreateMessage(string jobName, IEnumerable<(string Name, string? Value, bool IgnoreIfNull)> details)
{
var message = new System.Text.StringBuilder();
message.AppendLine($"{jobName} could not be completed.");
message.AppendLine("─────────────────────────────────────────");
foreach (var (name, value, ignoreNullValue) in details)
{
if (ignoreNullValue && value is null)
continue;
message.AppendLine($" {name}: {value}");
}
message.AppendLine("─────────────────────────────────────────");
return message.ToString();
}
}