fix(PdfMergeBehavior): improve error diagnostics and exception messages in PdfMergeBehavior
- Added detailed request context to all MergeDocumentException messages - Clarified conversion error message from "converted to PDF/A" to "converted to byte" - Removed unused base64 conversion and redundant variable assignment - Improved code readability and string concatenation formatting
This commit is contained in:
parent
5b30465126
commit
e57e9e1834
@ -1,5 +1,4 @@
|
|||||||
#if WINDOWS
|
#if WINDOWS
|
||||||
using DevExpress.XtraReports;
|
|
||||||
using EnvelopeGenerator.Application.Common.Extensions;
|
using EnvelopeGenerator.Application.Common.Extensions;
|
||||||
using EnvelopeGenerator.Application.Exceptions;
|
using EnvelopeGenerator.Application.Exceptions;
|
||||||
using EnvelopeGenerator.Domain.Constants;
|
using EnvelopeGenerator.Domain.Constants;
|
||||||
@ -26,9 +25,9 @@ public class PdfMergeBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
|
|||||||
var doc = await next(cancel);
|
var doc = await next(cancel);
|
||||||
|
|
||||||
if (request.Report is null)
|
if (request.Report is null)
|
||||||
throw new InvalidOperationException("The final document report could not be merged." +
|
throw new InvalidOperationException("The final document report could not be merged."
|
||||||
"There may be an error related to the behavior register order." +
|
+ "There may be an error related to the behavior register order."
|
||||||
"Request details:\n" + request.ToJson(Format.Json.ForDiagnostics));
|
+ "Request details:\n" + request.ToJson(Format.Json.ForDiagnostics));
|
||||||
|
|
||||||
using var oDocumentStream = new MemoryStream(doc);
|
using var oDocumentStream = new MemoryStream(doc);
|
||||||
using var oReportStream = new MemoryStream(request.Report);
|
using var oReportStream = new MemoryStream(request.Report);
|
||||||
@ -42,31 +41,31 @@ public class PdfMergeBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
|
|||||||
|
|
||||||
oStatus = oDocumentPDF.GetStat();
|
oStatus = oDocumentPDF.GetStat();
|
||||||
if (oStatus != GdPictureStatus.OK)
|
if (oStatus != GdPictureStatus.OK)
|
||||||
throw new MergeDocumentException($"Document could not be loaded: {oStatus}");
|
throw new MergeDocumentException($"Document could not be loaded: {oStatus}."
|
||||||
|
+ "Request details:\n" + request.ToJson(Format.Json.ForDiagnostics));
|
||||||
|
|
||||||
// Load the report file into memory
|
// Load the report file into memory
|
||||||
oReportPDF.LoadFromStream(oReportStream, true);
|
oReportPDF.LoadFromStream(oReportStream, true);
|
||||||
oStatus = oReportPDF.GetStat();
|
oStatus = oReportPDF.GetStat();
|
||||||
if (oStatus != GdPictureStatus.OK)
|
if (oStatus != GdPictureStatus.OK)
|
||||||
throw new MergeDocumentException($"Report could not be loaded: {oStatus}");
|
throw new MergeDocumentException($"Report could not be loaded: {oStatus}."
|
||||||
|
+ "Request details:\n" + request.ToJson(Format.Json.ForDiagnostics));
|
||||||
|
|
||||||
// Merge the documents
|
// Merge the documents
|
||||||
var oMergedPDF = oDocumentPDF.Merge2Documents(oDocumentPDF, oReportPDF);
|
var oMergedPDF = oDocumentPDF.Merge2Documents(oDocumentPDF, oReportPDF);
|
||||||
oStatus = oMergedPDF.GetStat();
|
oStatus = oMergedPDF.GetStat();
|
||||||
if (oStatus != GdPictureStatus.OK)
|
if (oStatus != GdPictureStatus.OK)
|
||||||
throw new MergeDocumentException($"Documents could not be merged: {oStatus}");
|
throw new MergeDocumentException($"Documents could not be merged: {oStatus}."
|
||||||
|
+ "Request details:\n" + request.ToJson(Format.Json.ForDiagnostics));
|
||||||
|
|
||||||
// Convert to byte
|
// Convert to byte
|
||||||
oMergedPDF.SaveToStream(oFinalStream);
|
oMergedPDF.SaveToStream(oFinalStream);
|
||||||
oStatus = oDocumentPDF.GetStat();
|
oStatus = oDocumentPDF.GetStat();
|
||||||
if (oStatus != GdPictureStatus.OK)
|
if (oStatus != GdPictureStatus.OK)
|
||||||
throw new MergeDocumentException($"Document could not be converted to PDF/A: {oStatus}");
|
throw new MergeDocumentException($"Document could not be converted to byte: {oStatus}."
|
||||||
|
+ "Request details:\n" + request.ToJson(Format.Json.ForDiagnostics));
|
||||||
|
|
||||||
doc = oFinalStream.ToArray();
|
return oFinalStream.ToArray();
|
||||||
|
|
||||||
string base64String = Convert.ToBase64String(doc);
|
|
||||||
|
|
||||||
return doc;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
Loading…
x
Reference in New Issue
Block a user