Falls back to the application layout when the active theme cannot be loaded

This commit is contained in:
BinaryAlley committed 2026-08-21 09:42:30 -07:00
1 parent a09876525b
commit 170b3a0917
2 files changed
+30

No files matched your search

@@ -2,6 +2,7 @@
using Lumina.Presentation.Web.Common.DTO.Themes; using Lumina.Presentation.Web.Common.DTO.Themes;
using Lumina.Presentation.Web.Common.Primitives; using Lumina.Presentation.Web.Common.Primitives;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
@@ -48,6 +49,8 @@ public class ThemeLayoutRenderer
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param> /// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the full page HTML, or an error.</returns> /// <returns>An <see cref="Result{TValue}"/> containing either the full page HTML, or an error.</returns>
public virtual async Task<Result<string>> RenderAsync(ThemeLayoutPageDto page, string? requestedThemeId = null, CancellationToken cancellationToken = default) public virtual async Task<Result<string>> RenderAsync(ThemeLayoutPageDto page, string? requestedThemeId = null, CancellationToken cancellationToken = default)
{
try
{ {
ThemeRenderDocumentDto layoutDocument = await _themeService.GetRenderDocumentAsync(LAYOUT_PAGE_KEY, requestedThemeId, cancellationToken); ThemeRenderDocumentDto layoutDocument = await _themeService.GetRenderDocumentAsync(LAYOUT_PAGE_KEY, requestedThemeId, cancellationToken);
string themeId = layoutDocument.Theme.Id; string themeId = layoutDocument.Theme.Id;
@@ -75,6 +78,18 @@ public class ThemeLayoutRenderer
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.");
}
}
/// <summary> /// <summary>
/// Renders the navigation menu of the active theme, falling back to the application Razor menu when the theme template cannot be rendered. /// Renders the navigation menu of the active theme, falling back to the application Razor menu when the theme template cannot be rendered.
@@ -2,6 +2,7 @@
using Lumina.Presentation.Web.Common.DTO.Themes; using Lumina.Presentation.Web.Common.DTO.Themes;
using Lumina.Presentation.Web.Common.Primitives; using Lumina.Presentation.Web.Common.Primitives;
using Lumina.Presentation.Web.Common.Services; using Lumina.Presentation.Web.Common.Services;
using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
@@ -35,6 +36,8 @@ public class ThemePageRenderer
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param> /// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the rendered page, or an error.</returns> /// <returns>An <see cref="Result{TValue}"/> containing either the rendered page, or an error.</returns>
public virtual async Task<Result<ThemePageRenderResultDto>> RenderAsync(ThemePageDto model, string? requestedThemeId = null, CancellationToken cancellationToken = default) public virtual async Task<Result<ThemePageRenderResultDto>> RenderAsync(ThemePageDto model, string? requestedThemeId = null, CancellationToken cancellationToken = default)
{
try
{ {
ThemeRenderDocumentDto document = await _themeService.GetRenderDocumentAsync(model.PageKey, requestedThemeId, cancellationToken); ThemeRenderDocumentDto document = await _themeService.GetRenderDocumentAsync(model.PageKey, requestedThemeId, cancellationToken);
@@ -45,4 +48,16 @@ public class ThemePageRenderer
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.");
}
}
} }