From 6ae066d1e99fe3bfd0f82cb72fed24f35cede756 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Wed, 14 Aug 2024 14:44:41 +0800 Subject: [PATCH] Add OnSectionRenderingErrorAsync and slow down with crawling --- .../Pages/Documents/Project/Index.cshtml.cs | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) 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 7789582f81..895e1c3085 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 @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; +using System.Net; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -549,12 +550,7 @@ namespace Volo.Docs.Pages.Documents.Project } 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 - }); + await OnSectionRenderingErrorAsync(e); } } @@ -578,6 +574,19 @@ namespace Volo.Docs.Pages.Documents.Project Document.Content = content; } + + protected 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> GetDocumentPartialTemplatesAsync() {