Skip to content
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

Fixed: Blazor Exception handling doesn't show the error message #5791

Merged
merged 3 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling
{
public class AbpExceptionHandlingLogger : ILogger, IDisposable
public class AbpExceptionHandlingLogger : ILogger
{
private readonly IServiceCollection _serviceCollection;
private IServiceScope _serviceScope;
private IUserExceptionInformer _userExceptionInformer;

public AbpExceptionHandlingLogger(IServiceCollection serviceCollection)
Expand Down Expand Up @@ -39,7 +38,7 @@ public virtual void Log<TState>(
return;
}

_userExceptionInformer.InformAsync(new UserExceptionInformerContext(exception));
_userExceptionInformer.Inform(new UserExceptionInformerContext(exception));
}

protected virtual void TryInitialize()
Expand All @@ -50,8 +49,7 @@ protected virtual void TryInitialize()
return;
}

_serviceScope = serviceProvider.CreateScope();
_userExceptionInformer = _serviceScope.ServiceProvider.GetRequiredService<IUserExceptionInformer>();
_userExceptionInformer = serviceProvider.GetRequiredService<IUserExceptionInformer>();
}

public virtual bool IsEnabled(LogLevel logLevel)
Expand All @@ -63,10 +61,5 @@ public virtual IDisposable BeginScope<TState>(TState state)
{
return NullDisposable.Instance;
}

public virtual void Dispose()
{
_serviceScope?.Dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ILogger CreateLogger(string categoryName)

public void Dispose()
{
_logger.Dispose();

}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using System.Threading.Tasks;

namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling
namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling
{
public interface IUserExceptionInformer
{
Task InformAsync(UserExceptionInformerContext context);
void Inform(UserExceptionInformerContext context);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.AspNetCore.ExceptionHandling;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Http;
Expand All @@ -9,19 +11,32 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling
{
public class UserExceptionInformer : IUserExceptionInformer, ITransientDependency
{
public ILogger<UserExceptionInformer> Logger { get; set; }
protected IUiMessageService MessageService { get; }
protected IExceptionToErrorInfoConverter ExceptionToErrorInfoConverter { get; }

public UserExceptionInformer(IUiMessageService messageService, IExceptionToErrorInfoConverter exceptionToErrorInfoConverter)
public UserExceptionInformer(
IUiMessageService messageService,
IExceptionToErrorInfoConverter exceptionToErrorInfoConverter)
{
MessageService = messageService;
ExceptionToErrorInfoConverter = exceptionToErrorInfoConverter;
Logger = NullLogger<UserExceptionInformer>.Instance;
}

public virtual async Task InformAsync(UserExceptionInformerContext context)
public void Inform(UserExceptionInformerContext context)
{
var errorInfo = GetErrorInfo(context);
await ShowErrorInfoAsync(errorInfo);

if (errorInfo.Details.IsNullOrEmpty())
{
//TODO: Should we introduce MessageService.Error (sync) method instead of such a usage (without await)..?
MessageService.ErrorAsync(errorInfo.Message);
}
else
{
MessageService.ErrorAsync(errorInfo.Details, errorInfo.Message);
}
}

protected virtual RemoteServiceErrorInfo GetErrorInfo(UserExceptionInformerContext context)
Expand All @@ -33,17 +48,5 @@ protected virtual RemoteServiceErrorInfo GetErrorInfo(UserExceptionInformerConte

return ExceptionToErrorInfoConverter.Convert(context.Exception, false);
}

protected virtual async Task ShowErrorInfoAsync(RemoteServiceErrorInfo errorInfo)
{
if (errorInfo.Details.IsNullOrEmpty())
{
await MessageService.ErrorAsync(errorInfo.Message);
}
else
{
await MessageService.ErrorAsync(errorInfo.Details, errorInfo.Message);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

namespace Volo.Abp.AspNetCore.Components.WebAssembly
{
//TODO: Implement with sweetalert in a new package
public class UiMessageService : IUiMessageService, ITransientDependency
public class SimpleUiMessageService : IUiMessageService, ITransientDependency
{
protected IJSRuntime JsRuntime { get; }

public UiMessageService(IJSRuntime jsRuntime)
public SimpleUiMessageService(IJSRuntime jsRuntime)
{
JsRuntime = jsRuntime;
}
Expand Down