using System; namespace ECMJobRunner.Application.Common.Exceptions { /// /// Exception thrown when a DEX job operation fails /// public class DEXJobException : Exception { /// /// Initializes a new instance with an inner exception /// /// Name of the query that failed /// Batch ID associated with the operation /// SQL query that was executed (nullable) /// The inner exception that caused the failure public DEXJobException(string queryName, string batchId, string? sqlQuery, Exception innerException) : base( $"[SQL Execution Failure] Query '{queryName}' could not be completed for Batch '{batchId}'." + Environment.NewLine + "─────────────────────────────────────────" + Environment.NewLine + " Query:" + (sqlQuery is null ? string.Empty : Environment.NewLine + $" {sqlQuery}") + Environment.NewLine + Environment.NewLine + " Root Cause:" + Environment.NewLine + $" {innerException?.Message}" + Environment.NewLine + "─────────────────────────────────────────", innerException) { SqlQuery = sqlQuery; BatchId = batchId; QueryName = queryName; } /// /// Initializes a new instance with a reason message /// /// Name of the query that failed /// Batch ID associated with the operation /// SQL query that was executed (nullable) /// Reason for the failure public DEXJobException(string queryName, string batchId, string? sqlQuery, string reason) : base( $"[SQL Execution Failure] Query '{queryName}' could not be completed for Batch '{batchId}'." + Environment.NewLine + "─────────────────────────────────────────" + Environment.NewLine + " Query:" + (sqlQuery is null ? string.Empty : Environment.NewLine + $" {sqlQuery}") + Environment.NewLine + Environment.NewLine + " Reason:" + Environment.NewLine + $" {reason}" + Environment.NewLine + "─────────────────────────────────────────") { SqlQuery = sqlQuery; BatchId = batchId; QueryName = queryName; } /// /// Gets the SQL query that failed (if available) /// public string? SqlQuery { get; } /// /// Gets the batch ID associated with the operation /// public string BatchId { get; } /// /// Gets the name of the query that failed /// public string QueryName { get; } } }