Skip to content

Commit aab534f

Browse files
committed
handle parsing exceptions on BitMarkdownViewer initilization #11008
1 parent 6100458 commit aab534f

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/BlazorUI/Bit.BlazorUI.Extras/Components/MarkdownViewer/BitMarkdownViewer.razor.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,30 @@ public partial class BitMarkdownViewer : BitComponentBase
2828

2929
protected override async Task OnInitializedAsync()
3030
{
31-
_html = await _markdownService.Parse(Markdown, _cts.Token);
32-
33-
StateHasChanged();
31+
await ParseAndRender();
3432

3533
await base.OnInitializedAsync();
3634
}
3735

3836

3937

40-
private async Task OnMarkdownSet()
38+
private void OnMarkdownSet()
4139
{
4240
if (IsRendered is false) return;
4341

44-
await ParseAndRender();
42+
_ = ParseAndRender();
4543
}
4644

4745
private async Task ParseAndRender()
4846
{
49-
_html = await _markdownService.Parse(Markdown, _cts.Token);
47+
try
48+
{
49+
_html = await _markdownService.Parse(Markdown, _cts.Token);
50+
}
51+
catch
52+
{
53+
_html = "<b>Failed to parse the markdown!</b>";
54+
}
5055

5156
StateHasChanged();
5257
}

0 commit comments

Comments
 (0)