Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4278

Show details of uncaught exception in Blazor UI

$
0
0

We have a customer that is using a custom browser, which doesn't allow them to open the console to see the logged error messages. Unfortunately we don't have access to their system so we need to somehow get the exception message and stack trace.

I tried to build a custom ErrorBoundary (https://blazorschool.com/tutorial/blazor-server/dotnet7/error-handling-101402) but the problem is, that this will only either show the error message or the content, even though I render both:

CustomErrorBoundary.cs:

...    protected override void BuildRenderTree(RenderTreeBuilder builder)    {        if (ErrorContent is not null)        {                builder.AddContent(0, ErrorContent(CurrentException));        }        builder.AddContent(1, ChildContent);    }...

App.razor:

<CustomErrorBoundary @ref="@errorBoundary"><ChildContent><CascadingAuthenticationState><Router AppAssembly="@typeof(App).Assembly"><Found Context="routeData"><AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"><NotAuthorized><Unauthorized></Unauthorized></NotAuthorized></AuthorizeRouteView><FocusOnNavigate RouteData="@routeData" Selector="h1" /></Found><NotFound><AppPageTitle PageTitle="@Frontend.ErrotPage_NotFoundTitle" /><LayoutView Layout="@typeof(MainLayout)"><MudAlert Severity="Severity.Error" Variant="Variant.Filled" Square="true" Class="ma-2">@Frontend.ErrorPage_NotFound</MudAlert></LayoutView></NotFound></Router></CascadingAuthenticationState></ChildContent><ErrorContent Context="Exception"><p>An error occured.</p>        @if (Exception != null)        {<p>@Exception.Message</p>        }</ErrorContent></CustomErrorBoundary>

What I would need is to extend the default blazor error message ("An unhandled error has occurred. Reload") with a button to expand the exception message and stack trace. As far as I understand that is not possible, because it's in the index.html file.

Is there a way to still show the content and let the user continue using the website, even though there is an exception and also show the exception details?

I know I can setup the logger to send the logs to the API, but there might be exceptions that happen before the connection to the API is there.


Viewing all articles
Browse latest Browse all 4278

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>