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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user