91 lines
2.8 KiB
Plaintext
91 lines
2.8 KiB
Plaintext
@using TIAMWebApp.Shared.Application.Utility
|
|
@using AyCode.Core.Extensions
|
|
@using AyCode.Core.Loggers
|
|
@using AyCode.Services.Loggers
|
|
@using AyCode.Utils.Extensions
|
|
@inject IJSRuntime jsRuntime
|
|
@inject IEnumerable<IAcLogWriterClientBase> LogWriters
|
|
|
|
@inherits ErrorBoundary
|
|
|
|
@* <DxPopup @ref="ErrorPopup" HeaderText="Popup"/> *@
|
|
|
|
@code {
|
|
bool PopupVisible { get; set; } = false;
|
|
}
|
|
|
|
@if (_currentError != null)
|
|
{
|
|
@* <CascadingValue Value=PopupMessageBox> *@
|
|
<div class="error-message">
|
|
<p>An error has occurred: @_currentError.Message</p>
|
|
</div>
|
|
@* </CascadingValue>
|
|
<PopupMessageBox @ref="PopupMessageBox" /> *@
|
|
}
|
|
else
|
|
{
|
|
@ChildContent
|
|
}
|
|
|
|
@code {
|
|
//public DxPopup ErrorPopup;
|
|
private Exception? _currentError;
|
|
private LoggerClient _logger;
|
|
|
|
//public PopupMessageBox PopupMessageBox { get; private set; } = default!;
|
|
|
|
[Parameter] public string LoggerCategory { get; set; }
|
|
[Parameter] public EventCallback<Exception> OnError { get; set; }
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
_logger = new LoggerClient(LoggerCategory, LogWriters.ToArray());
|
|
|
|
base.OnInitialized();
|
|
}
|
|
|
|
// private void HandleError(Exception exception) //, [CallerMemberName] string? memberName = null)
|
|
// {
|
|
// }
|
|
|
|
protected override async Task OnErrorAsync(Exception exception)
|
|
{
|
|
_currentError = exception;
|
|
|
|
exception.GetCategoryAndMemberNameFromStackTraceString(out var memberName, out var categoryName);
|
|
|
|
if (memberName.IsNullOrWhiteSpace()) memberName = "..."; //ne az "OnErrorAsync" memberName-el logoljunk! - J.
|
|
|
|
try
|
|
{
|
|
_logger.Writer<SignaRClientLogItemWriter>()?.Error($"An error occurred: {exception.Message}", exception, categoryName, memberName);
|
|
}
|
|
catch (Exception loggerException)
|
|
{
|
|
await jsRuntime.InvokeVoidAsync("console.error", $"{nameof(TiamErrorBoundaryComponent)}->OnErrorAsync; Logger error! {loggerException}");
|
|
|
|
await jsRuntime.InvokeVoidAsync("console.error", $"{nameof(TiamErrorBoundaryComponent)}->{memberName}; An error occurred: {exception}");
|
|
//jsRuntime.InvokeVoidAsync("console.warn", $"{nameof(TiamErrorBoundaryComponent)}->{memberName}; Error details: {exception.StackTrace}");
|
|
}
|
|
|
|
await Task.Delay(500); //KELL IDE, KÜLÖNBEN NEM MEGY KI A LOG A SZERVERRE! - J.
|
|
|
|
//ShowErrorNotification("An unexpected error occurred. Please try again later.");
|
|
|
|
if (OnError.HasDelegate) await OnError.InvokeAsync(exception);
|
|
else await base.OnErrorAsync(exception);
|
|
}
|
|
|
|
// private void ShowErrorNotification(string message)
|
|
// {
|
|
// jsRuntime.InvokeVoidAsync("alert", message);
|
|
// }
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
_currentError = null;
|
|
}
|
|
}
|
|
|