diff --git a/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Documents/DocumentRenderErrorEvent.cs b/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Documents/DocumentRenderErrorEvent.cs new file mode 100644 index 0000000000..2f30099576 --- /dev/null +++ b/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Documents/DocumentRenderErrorEvent.cs @@ -0,0 +1,8 @@ +namespace Volo.Docs.Documents; + +public class DocumentRenderErrorEvent +{ + public string Name { get; set; } + + public string ErrorMessage { get; set; } +} \ No newline at end of file diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs index c3c1ae9643..7789582f81 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs @@ -16,6 +16,7 @@ using Volo.Abp.Application.Dtos; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Abp.Data; using Volo.Abp.Domain.Entities; +using Volo.Abp.EventBus.Local; using Volo.Docs.Documents; using Volo.Docs.HtmlConverting; using Volo.Docs.Models; @@ -96,6 +97,8 @@ namespace Volo.Docs.Pages.Documents.Project private readonly DocsUiOptions _uiOptions; protected IDocsLinkGenerator DocsLinkGenerator => LazyServiceProvider.LazyGetRequiredService(); + + protected ILocalEventBus LocalEventBus => LazyServiceProvider.LazyGetRequiredService(); public IndexModel( IDocumentAppService documentAppService, @@ -540,7 +543,19 @@ namespace Volo.Docs.Pages.Documents.Project DocumentNavigationsDto = await _documentSectionRenderer.GetDocumentNavigationsAsync(Document.Content); - Document.Content = await _documentSectionRenderer.RenderAsync(Document.Content, UserPreferences, partialTemplates); + try + { + Document.Content = await _documentSectionRenderer.RenderAsync(Document.Content, UserPreferences, partialTemplates); + } + catch (Exception e) + { + var message = $"Error occurred during the rendering of this document. The document is not valid: {e.Message}"; + Document.Content = $"````txt{Environment.NewLine}{message}{Environment.NewLine}````"; + await LocalEventBus.PublishAsync(new DocumentRenderErrorEvent + { + ErrorMessage = message, Name = Document.Name + }); + } } var converter = _documentToHtmlConverterFactory.Create(Document.Format ?? Project.Format);