diff --git a/src/Lumina.Presentation.Web/Core/Themes/ThemeLayoutRenderer.cs b/src/Lumina.Presentation.Web/Core/Themes/ThemeLayoutRenderer.cs
index 65a7ca79..69540cac 100644
--- a/src/Lumina.Presentation.Web/Core/Themes/ThemeLayoutRenderer.cs
+++ b/src/Lumina.Presentation.Web/Core/Themes/ThemeLayoutRenderer.cs
@@ -2,6 +2,7 @@
using Lumina.Presentation.Web.Common.DTO.Themes;
using Lumina.Presentation.Web.Common.Primitives;
using Microsoft.AspNetCore.Http;
+using System;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -49,31 +50,45 @@ public class ThemeLayoutRenderer
/// An containing either the full page HTML, or an error.
public virtual async Task> RenderAsync(ThemeLayoutPageDto page, string? requestedThemeId = null, CancellationToken cancellationToken = default)
{
- ThemeRenderDocumentDto layoutDocument = await _themeService.GetRenderDocumentAsync(LAYOUT_PAGE_KEY, requestedThemeId, cancellationToken);
- string themeId = layoutDocument.Theme.Id;
- bool isAuthenticated = _httpContextAccessor.HttpContext?.User.Identity?.IsAuthenticated == true;
+ try
+ {
+ ThemeRenderDocumentDto layoutDocument = await _themeService.GetRenderDocumentAsync(LAYOUT_PAGE_KEY, requestedThemeId, cancellationToken);
+ string themeId = layoutDocument.Theme.Id;
+ bool isAuthenticated = _httpContextAccessor.HttpContext?.User.Identity?.IsAuthenticated == true;
- string appHead = await _viewRenderer.RenderPartialAsync("_ThemeLayoutHead", cancellationToken);
- string nav = await RenderNavAsync(themeId, cancellationToken);
- string audioPlayer = isAuthenticated ? await _viewRenderer.RenderPartialAsync("_AudioPlayer", cancellationToken) : string.Empty;
- string appScripts = await _viewRenderer.RenderPartialAsync("_ThemeLayoutScripts", cancellationToken);
+ string appHead = await _viewRenderer.RenderPartialAsync("_ThemeLayoutHead", cancellationToken);
+ string nav = await RenderNavAsync(themeId, cancellationToken);
+ string audioPlayer = isAuthenticated ? await _viewRenderer.RenderPartialAsync("_AudioPlayer", cancellationToken) : string.Empty;
+ string appScripts = await _viewRenderer.RenderPartialAsync("_ThemeLayoutScripts", cancellationToken);
- ThemeLayoutModelDto layoutModel = new(
- page.Title,
- $"/theme-assets/{themeId}/assets",
- appHead,
- nav,
- page.Content,
- audioPlayer,
- appScripts,
- page.Script,
- isAuthenticated ? string.Empty : "bottom: 0px;");
+ ThemeLayoutModelDto layoutModel = new(
+ page.Title,
+ $"/theme-assets/{themeId}/assets",
+ appHead,
+ nav,
+ page.Content,
+ audioPlayer,
+ appScripts,
+ page.Script,
+ isAuthenticated ? string.Empty : "bottom: 0px;");
- Result renderResult = _templateEngine.RenderPage(layoutDocument.Template, layoutModel);
- if (renderResult.IsFailure)
- return renderResult.Errors;
+ Result renderResult = _templateEngine.RenderPage(layoutDocument.Template, layoutModel);
+ if (renderResult.IsFailure)
+ return renderResult.Errors;
- return renderResult.Value.Content;
+ return renderResult.Value.Content;
+ }
+ catch (OperationCanceledException)
+ {
+ throw;
+ }
+ catch (Exception)
+ {
+ // the themed shell is best effort: when the active theme cannot be loaded, the application layout renders the
+ // page instead. The exception must not propagate, otherwise the exception handling middleware turns the page
+ // into a JSON error instead of the fallback layout, so any page breaks whenever the theme API is unavailable.
+ return Error.NotFound(code: "Theme.Template.Unavailable", description: "The active theme could not be loaded.");
+ }
}
///
diff --git a/src/Lumina.Presentation.Web/Core/Themes/ThemePageRenderer.cs b/src/Lumina.Presentation.Web/Core/Themes/ThemePageRenderer.cs
index bbcc3f8b..2dc72ac6 100644
--- a/src/Lumina.Presentation.Web/Core/Themes/ThemePageRenderer.cs
+++ b/src/Lumina.Presentation.Web/Core/Themes/ThemePageRenderer.cs
@@ -2,6 +2,7 @@
using Lumina.Presentation.Web.Common.DTO.Themes;
using Lumina.Presentation.Web.Common.Primitives;
using Lumina.Presentation.Web.Common.Services;
+using System;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -36,13 +37,27 @@ public class ThemePageRenderer
/// An containing either the rendered page, or an error.
public virtual async Task> RenderAsync(ThemePageDto model, string? requestedThemeId = null, CancellationToken cancellationToken = default)
{
- ThemeRenderDocumentDto document = await _themeService.GetRenderDocumentAsync(model.PageKey, requestedThemeId, cancellationToken);
+ try
+ {
+ ThemeRenderDocumentDto document = await _themeService.GetRenderDocumentAsync(model.PageKey, requestedThemeId, cancellationToken);
- model.ThemeId = document.Theme.Id;
- model.AssetBase = $"/theme-assets/{document.Theme.Id}/assets";
- // a fresh script id per render lets the AJAX navigator unload this view's script when navigating away
- model.ScriptId = ScriptIdentifierHelper.GenerateScriptId();
+ model.ThemeId = document.Theme.Id;
+ model.AssetBase = $"/theme-assets/{document.Theme.Id}/assets";
+ // a fresh script id per render lets the AJAX navigator unload this view's script when navigating away
+ model.ScriptId = ScriptIdentifierHelper.GenerateScriptId();
- return _templateEngine.RenderPage(document.Template, model);
+ return _templateEngine.RenderPage(document.Template, model);
+ }
+ catch (OperationCanceledException)
+ {
+ throw;
+ }
+ catch (Exception)
+ {
+ // themed rendering is best effort: when the active theme cannot be loaded, the caller falls back to the Razor
+ // view. The exception must not propagate, otherwise the exception handling middleware turns the page into a
+ // JSON error instead of the Razor fallback, so any themed page breaks whenever the theme API is unavailable.
+ return Error.NotFound(code: "Theme.Template.Unavailable", description: "The active theme could not be loaded.");
+ }
}
}