From b4910cf5c380c3adb60a3893fb449badf2b0389d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20H=C3=B6rner?= Date: Sun, 1 Mar 2026 08:06:20 +0100 Subject: [PATCH] Changed error handling inside base renderer --- .../Endpoints/Documents/GetDocumentPdfEndpoint.cs | 10 +++------- .../Renderer/RendererTestBase.cs | 4 +--- .../Renderer/DocumentRendererBase.cs | 6 ++---- .../Renderer/IDocumentRenderer.cs | 2 +- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/Turnierplan.App/Endpoints/Documents/GetDocumentPdfEndpoint.cs b/src/Turnierplan.App/Endpoints/Documents/GetDocumentPdfEndpoint.cs index 7f13a035..7c3187fb 100644 --- a/src/Turnierplan.App/Endpoints/Documents/GetDocumentPdfEndpoint.cs +++ b/src/Turnierplan.App/Endpoints/Documents/GetDocumentPdfEndpoint.cs @@ -78,8 +78,6 @@ private static async Task Handle( // Wrap the code below in a transaction such that the generation count // is only incremented when the document is rendered successfully. - bool isSuccessful; - await using (var transaction = await repository.UnitOfWork.WrapTransactionAsync()) { document.IncreaseGenerationCount(); @@ -90,13 +88,11 @@ private static async Task Handle( document.Tournament.ShiftToTimezone(timeZoneInfo); document.Tournament.Compute(); - isSuccessful = renderer.Render(document.Tournament, configuration, localization, stream); + renderer.Render(document.Tournament, configuration, localization, stream); - transaction.ShouldCommit = isSuccessful; + transaction.ShouldCommit = true; } - return isSuccessful - ? Results.File(stream.ToArray(), "application/pdf") - : Results.InternalServerError(); + return Results.File(stream.ToArray(), "application/pdf"); } } diff --git a/src/Turnierplan.PdfRendering.Test.Unit/Renderer/RendererTestBase.cs b/src/Turnierplan.PdfRendering.Test.Unit/Renderer/RendererTestBase.cs index f9ed36e2..bae2eb06 100644 --- a/src/Turnierplan.PdfRendering.Test.Unit/Renderer/RendererTestBase.cs +++ b/src/Turnierplan.PdfRendering.Test.Unit/Renderer/RendererTestBase.cs @@ -58,9 +58,7 @@ protected void AssertRender(Tournament tournament, IDocumentConfiguration config __serviceProvider.GetRequiredService().TryGetLocalization(languageCode, out var localization).Should().BeTrue(); using var stream = new MemoryStream(); - var isSuccessful = GetRenderer().Render(tournament, configuration, new LocalizationWrapper(localization!), stream); - - isSuccessful.Should().BeTrue(); + GetRenderer().Render(tournament, configuration, new LocalizationWrapper(localization!), stream); var pdfData = stream.ToArray(); diff --git a/src/Turnierplan.PdfRendering/Renderer/DocumentRendererBase.cs b/src/Turnierplan.PdfRendering/Renderer/DocumentRendererBase.cs index d6b4b6e7..ad43f622 100644 --- a/src/Turnierplan.PdfRendering/Renderer/DocumentRendererBase.cs +++ b/src/Turnierplan.PdfRendering/Renderer/DocumentRendererBase.cs @@ -20,7 +20,7 @@ private protected DocumentRendererBase() protected Activity? CurrentActivity { get; private set; } - public bool Render(Tournament tournament, IDocumentConfiguration configuration, ILocalization localization, Stream destination) + public void Render(Tournament tournament, IDocumentConfiguration configuration, ILocalization localization, Stream destination) { lock (this) { @@ -53,7 +53,7 @@ public bool Render(Tournament tournament, IDocumentConfiguration configuration, CurrentActivity?.AddException(ex); CurrentActivity?.Stop(); - return false; + throw; } finally { @@ -66,8 +66,6 @@ public bool Render(Tournament tournament, IDocumentConfiguration configuration, // Ignored } } - - return true; } protected abstract Document Render(Tournament tournament, T configuration, ILocalization localization); diff --git a/src/Turnierplan.PdfRendering/Renderer/IDocumentRenderer.cs b/src/Turnierplan.PdfRendering/Renderer/IDocumentRenderer.cs index 9a2b9ded..af0c2c49 100644 --- a/src/Turnierplan.PdfRendering/Renderer/IDocumentRenderer.cs +++ b/src/Turnierplan.PdfRendering/Renderer/IDocumentRenderer.cs @@ -8,5 +8,5 @@ public interface IDocumentRenderer { Type DocumentConfigurationType { get; } - bool Render(Tournament tournament, IDocumentConfiguration configuration, ILocalization localization, Stream destination); + void Render(Tournament tournament, IDocumentConfiguration configuration, ILocalization localization, Stream destination); }