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