New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blazor server side better error UI #8195
Comments
Any updates on this one? |
There have been investigations, but the results were unsatisfactory due to some limitations. However, we will close the problem once we have found a satisfactory solution. |
So what's the workaround so far? Catching the exception in the component's code on the Blazor side? If so, how do I open the exception modal with the message? |
Yes, we try to ensure that there are no unhandled exceptions as mentioned in Microsoft's documentation. By the way, you can see the work done within the scope of this issue here. |
Abp 7.3.3 It can be done easily by creating the in blazor components, every events will be called from
public abstract class MyComponentBase : IComponent, IHandleEvent, IHandleAfterRender
{
...
Task IHandleEvent.HandleEventAsync(EventCallbackWorkItem callback, object? arg)
{
var task = callback.InvokeAsync(arg);
var shouldAwaitTask = task.Status != TaskStatus.RanToCompletion &&
task.Status != TaskStatus.Canceled;
// After each event, we synchronously re-render (unless !ShouldRender())
// This just saves the developer the trouble of putting "StateHasChanged();"
// at the end of every event callback.
StateHasChanged();
return shouldAwaitTask ?
CallStateHasChangedOnAsyncCompletion(task) :
Task.CompletedTask;
}
...
} Then task will be run in private async Task CallStateHasChangedOnAsyncCompletion(Task task)
{
try
{
await task;
}
catch // avoiding exception filters for AOT runtime support
{
// Ignore exceptions from task cancellations, but don't bother issuing a state change.
if (task.IsCanceled)
{
return;
}
throw;
}
StateHasChanged();
}
protected virtual Task OnCallStateHasChangedOnAsyncCompletionExceptionAsync(AggregateException? exception)
=> Task.CompletedTask; Make sure to set the
private async Task CallStateHasChangedOnAsyncCompletion(Task task)
{
try
{
await task;
}
catch // avoiding exception filters for AOT runtime support
{
// Ignore exceptions from task cancellations, but don't bother issuing a state change.
if (task.IsCanceled)
{
return;
}
await OnCallStateHasChangedOnAsyncCompletionExceptionAsync(task.Exception);
}
StateHasChanged();
}
protected override Task OnCallStateHasChangedOnAsyncCompletionExceptionAsync(AggregateException? exception)
{
return HandleErrorAsync(exception);
}
In the private async Task RunInitAndSetParametersAsync()
{
try
{
...
}
catch (Exception ex)
{
await OnRunInitAndSetParametersExceptionAsync(ex);
}
}
public virtual Task OnRunInitAndSetParametersExceptionAsync(Exception ex) => Task.CompletedTask; In public override Task OnRunInitAndSetParametersExceptionAsync(Exception ex)
{
return HandleErrorAsync(ex);
} With Regards |
I bumped into it in ABP 7.4.0 commercial: |
Please check the logs of the backend app, and create a new issue. Thanks. |
|
We'd implemented a custom logger to show errors for Blazor WASM. For server side, global exception handling is not possible yet (see dotnet/aspnetcore#30940). However, we can still show a better messagebox (modal dialog) instead of the yellow bottom bar, for blazor server side. We can provide an option to the user to refresh the page in this modal dialog (message modal can have two options: Close & Refresh Page).
However, this should be carefully implemented. Because, if we handle every error and try to show message, it won't work. We should only handle the errors for blazor application's page, not other HTTP requests and MVC page requests.
The text was updated successfully, but these errors were encountered: