Browse Source

Add DocumentRenderErrorEvent

pull/20463/head
liangshiwei 2 years ago
parent
commit
3b7ab9a47e
  1. 8
      modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Documents/DocumentRenderErrorEvent.cs
  2. 17
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs

8
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; }
}

17
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<IDocsLinkGenerator>();
protected ILocalEventBus LocalEventBus => LazyServiceProvider.LazyGetRequiredService<ILocalEventBus>();
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);

Loading…
Cancel
Save