Browse Source

Merge pull request #20463 from abpframework/docerrorhandler

Add DocumentRenderErrorEvent
pull/20497/head
SALİH ÖZKARA 2 years ago
committed by GitHub
parent
commit
9fbc546100
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 8
      modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Documents/DocumentRenderErrorEvent.cs
  2. 26
      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; }
}

26
modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Net;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -16,6 +17,7 @@ using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
using Volo.Abp.Data; using Volo.Abp.Data;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.EventBus.Local;
using Volo.Docs.Documents; using Volo.Docs.Documents;
using Volo.Docs.HtmlConverting; using Volo.Docs.HtmlConverting;
using Volo.Docs.Models; using Volo.Docs.Models;
@ -96,6 +98,8 @@ namespace Volo.Docs.Pages.Documents.Project
private readonly DocsUiOptions _uiOptions; private readonly DocsUiOptions _uiOptions;
protected IDocsLinkGenerator DocsLinkGenerator => LazyServiceProvider.LazyGetRequiredService<IDocsLinkGenerator>(); protected IDocsLinkGenerator DocsLinkGenerator => LazyServiceProvider.LazyGetRequiredService<IDocsLinkGenerator>();
protected ILocalEventBus LocalEventBus => LazyServiceProvider.LazyGetRequiredService<ILocalEventBus>();
public IndexModel( public IndexModel(
IDocumentAppService documentAppService, IDocumentAppService documentAppService,
@ -540,7 +544,14 @@ namespace Volo.Docs.Pages.Documents.Project
DocumentNavigationsDto = await _documentSectionRenderer.GetDocumentNavigationsAsync(Document.Content); 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)
{
await OnSectionRenderingErrorAsync(e);
}
} }
var converter = _documentToHtmlConverterFactory.Create(Document.Format ?? Project.Format); var converter = _documentToHtmlConverterFactory.Create(Document.Format ?? Project.Format);
@ -563,6 +574,19 @@ namespace Volo.Docs.Pages.Documents.Project
Document.Content = content; Document.Content = content;
} }
protected virtual async Task OnSectionRenderingErrorAsync(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
});
// Slow down with crawling
HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
}
private async Task<List<DocumentPartialTemplateContent>> GetDocumentPartialTemplatesAsync() private async Task<List<DocumentPartialTemplateContent>> GetDocumentPartialTemplatesAsync()
{ {

Loading…
Cancel
Save