-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Background and Motivation
In our blazor server application we catch global errors in our system and report back, so our team knows when a user has encountered an unintended error. However, circuit exceptions are ones we are unable to monitor. So when a user gets a circuit exception we have trouble tracing back the original problem. I would like it if the UnhandledExcpetion in the CurcuitHost or Renderer was a publicly available event, or triggered a publicly available event somewhere else, so our app could intercept the exception and log it as desired.
Proposed API
This is just based on current code implementation. The event could also be exposed via a public interface, I'm just not sure where that would best be housed. I also assume this would be only for server side and not be used in WASM.
public sealed class Circuit
{
private readonly CircuitHost _circuitHost;
internal Circuit(CircuitHost circuitHost)
{
_circuitHost = circuitHost;
+ _circuitHost.UnhandledException += UnhandledExcpetion();
}
/// <summary>
/// Gets the identifier for the <see cref="Circuit"/>.
/// </summary>
public string Id => _circuitHost.CircuitId.Id;
+ public event UnhandledExceptionEventHandler UnhandledExcpetion;
+ public void UnhandledExcpetionCalled()
+ {
+ UnhandledExcpetion.Invoke();
+ }
}
Usage Examples
Host.cs
protected override async Task OnInitializedAsync()
{
var circuit = serviceProvider.GetRequiredService<Circuit>();
cirucit.UnhandledExcpetion += SendError;
}
private void SendError(Excpetion e)
{
//Whatever necessary handling of excpetion
}
Alternative Designs
This could also be an interface which listens to the Renderer or CircuitHost for unhandled exceptions. Something managed by DI to expose the event.
Risks
No risks to my knowledge. Potential pitfalls could be someone trying to respond to an unhandled exception poorly, but I think this is something users should be allowed to make a choice on.