Handle Errors in the Blazor Report Viewer
The Report Viewer displays the “Internal Server Error” toast in a browser for all exceptions. If you need to display a more detailed error message to end users, implement the IErrorNotifier interface and register your service at application startup.
The following code snippet creates a MyErrorNotifier class. The class is used to display a custom message to end users if a DataRetrievalException occurs:
using System;
using DevExpress.Blazor.Reporting.Services;
public class MyErrorNotifier : IErrorNotifier {
public event Action<string> OnErrorMessage;
public void ProcessError(Exception exception) {
string message = "Internal Server Error";
var dataRetrievalException = exception as DevExpress.XtraReports.DataRetrievalException;
if(dataRetrievalException != null && dataRetrievalException.InnerException is DevExpress.DataAccess.Sql.DatabaseConnectionException) {
message = "Please try again later.";
}
OnErrorMessage?.Invoke(message);
}
}
Register the MyErrorNotifier class at application startup (the Program.cs file):
builder.Services.AddScoped<IErrorNotifier, MyErrorNotifier>();
See Also