From d128d68609e7607a7009e2574550779cbcbe9e9a Mon Sep 17 00:00:00 2001 From: Enis Necipoglu Date: Tue, 17 Oct 2023 16:24:36 +0300 Subject: [PATCH 1/3] Show error instead of return 500 for Widget rendering --- .../Components/Contents/ContentFragment.cshtml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/ContentFragment.cshtml b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/ContentFragment.cshtml index 80834dd7fc..fcd3801667 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/ContentFragment.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/ContentFragment.cshtml @@ -1,4 +1,5 @@ @using Microsoft.AspNetCore.Mvc.ViewComponents +@using Microsoft.Extensions.Logging @using Volo.Abp.Data @using Volo.Abp.Reflection @using Volo.CmsKit.Contents @@ -9,6 +10,7 @@ @inject IMarkdownToHtmlRenderer MarkdownRenderer @inject IViewComponentSelector ViewComponentSelector +@inject ILogger Logger @foreach (var contentFragment in Model.ContentDto.ContentFragments) { @@ -35,6 +37,18 @@ } } - @await Component.InvokeAsync(componentName, parameters) + @try + { + await Component.InvokeAsync(componentName, parameters); + } + catch (Exception ex) + { + + + Logger.LogWarning(ex, $"Couldn't load the widget: {componentName}"); + } } } \ No newline at end of file From e78e5abe2b699db70641eaed70845dbd7311d0ea Mon Sep 17 00:00:00 2001 From: Enis Necipoglu Date: Tue, 17 Oct 2023 16:27:45 +0300 Subject: [PATCH 2/3] Localize the error --- .../CmsKit/Components/Contents/ContentFragment.cshtml | 8 +++++--- .../Volo/CmsKit/Localization/Resources/ar.json | 3 ++- .../Volo/CmsKit/Localization/Resources/cs.json | 3 ++- .../Volo/CmsKit/Localization/Resources/de-DE.json | 3 ++- .../Volo/CmsKit/Localization/Resources/el.json | 3 ++- .../Volo/CmsKit/Localization/Resources/en.json | 3 ++- .../Volo/CmsKit/Localization/Resources/es.json | 3 ++- .../Volo/CmsKit/Localization/Resources/fa.json | 3 ++- .../Volo/CmsKit/Localization/Resources/fi.json | 3 ++- .../Volo/CmsKit/Localization/Resources/fr.json | 3 ++- .../Volo/CmsKit/Localization/Resources/hi.json | 3 ++- .../Volo/CmsKit/Localization/Resources/hu.json | 3 ++- .../Volo/CmsKit/Localization/Resources/is.json | 3 ++- .../Volo/CmsKit/Localization/Resources/it.json | 3 ++- .../Volo/CmsKit/Localization/Resources/nl.json | 3 ++- .../Volo/CmsKit/Localization/Resources/pl-PL.json | 3 ++- .../Volo/CmsKit/Localization/Resources/pt-BR.json | 3 ++- .../Volo/CmsKit/Localization/Resources/ro-RO.json | 3 ++- .../Volo/CmsKit/Localization/Resources/ru.json | 3 ++- .../Volo/CmsKit/Localization/Resources/sk.json | 3 ++- .../Volo/CmsKit/Localization/Resources/sl.json | 3 ++- .../Volo/CmsKit/Localization/Resources/tr.json | 3 ++- .../Volo/CmsKit/Localization/Resources/vi.json | 3 ++- .../Volo/CmsKit/Localization/Resources/zh-Hans.json | 3 ++- .../Volo/CmsKit/Localization/Resources/zh-Hant.json | 3 ++- 25 files changed, 53 insertions(+), 27 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/ContentFragment.cshtml b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/ContentFragment.cshtml index fcd3801667..aad3de1abf 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/ContentFragment.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/ContentFragment.cshtml @@ -1,8 +1,10 @@ @using Microsoft.AspNetCore.Mvc.ViewComponents +@using Microsoft.Extensions.Localization @using Microsoft.Extensions.Logging @using Volo.Abp.Data @using Volo.Abp.Reflection @using Volo.CmsKit.Contents +@using Volo.CmsKit.Localization @using Volo.CmsKit.Web.Renderers; @using Volo.CmsKit.Web.Pages.CmsKit.Components.Contents; @@ -11,6 +13,7 @@ @inject IMarkdownToHtmlRenderer MarkdownRenderer @inject IViewComponentSelector ViewComponentSelector @inject ILogger Logger +@inject IStringLocalizer L @foreach (var contentFragment in Model.ContentDto.ContentFragments) { @@ -43,9 +46,8 @@ } catch (Exception ex) { - - Logger.LogWarning(ex, $"Couldn't load the widget: {componentName}"); + Logger.LogError(ex, $"Couldn't load the widget: {componentName}"); } } } \ No newline at end of file