From a39ef6a0e2e7ed785de7cb5f643cc65397e2d24b Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 9 Mar 2026 11:30:43 +0100 Subject: [PATCH] Improve error handling in FinalizeDocumentJob Added RethrowOnError property to control exception rethrowing during envelope finalization. Exceptions are now logged as errors and, if RethrowOnError is true, rethrown to enable stricter error handling and halt execution on failure. --- EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocumentJob.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocumentJob.cs b/EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocumentJob.cs index 9e336c80..5b405901 100644 --- a/EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocumentJob.cs +++ b/EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocumentJob.cs @@ -36,6 +36,8 @@ public class FinalizeDocumentJob(IOptions options, IConfiguration public byte[]? DocAsByte { get; set; } } + public bool RethrowOnError { get; set; } = true; + public async Task ExecuteAsync(CancellationToken cancel = default) { var gdPictureKey = _options.GdPictureLicenseKey; @@ -63,8 +65,10 @@ public class FinalizeDocumentJob(IOptions options, IConfiguration } catch (Exception ex) { - logger.LogError(ex); - logger.LogWarning(ex, "Unhandled exception while working envelope [{id}]", envelope.Id); + logger.LogError(ex, "Unhandled exception while working envelope [{id}]", envelope.Id); + + if(RethrowOnError) + throw; } logger.LogInformation("Envelope [{id}] finalized!", envelope.Id);