mirror of https://github.com/abpframework/abp.git
5 changed files with 87 additions and 13 deletions
@ -0,0 +1,10 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling |
|||
{ |
|||
public interface IUserExceptionInformer |
|||
{ |
|||
Task InformAsync(UserExceptionInformerContext context); |
|||
} |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Http.Client; |
|||
using Volo.Abp.Validation; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling |
|||
{ |
|||
public class UserExceptionInformer : IUserExceptionInformer, ITransientDependency |
|||
{ |
|||
private readonly IUiMessageService _messageService; |
|||
|
|||
public UserExceptionInformer(IUiMessageService messageService) |
|||
{ |
|||
_messageService = messageService; |
|||
} |
|||
|
|||
public virtual async Task InformAsync(UserExceptionInformerContext context) |
|||
{ |
|||
if (context.Exception is AbpRemoteCallException remoteCallException) |
|||
{ |
|||
await InformAbpRemoteCallExceptionAsync(remoteCallException, context); |
|||
} |
|||
else if (context.Exception is AbpValidationException validationException) |
|||
{ |
|||
await InformAbpValidationExceptionAsync(validationException, context); |
|||
} |
|||
} |
|||
|
|||
protected virtual async Task InformAbpRemoteCallExceptionAsync(AbpRemoteCallException exception, UserExceptionInformerContext context) |
|||
{ |
|||
if (exception.Error.Details.IsNullOrEmpty()) |
|||
{ |
|||
await _messageService.ErrorAsync(exception.Error.Message); |
|||
} |
|||
else |
|||
{ |
|||
await _messageService.ErrorAsync(exception.Error.Details, exception.Error.Message); |
|||
} |
|||
} |
|||
|
|||
protected virtual async Task InformAbpValidationExceptionAsync(AbpValidationException exception, UserExceptionInformerContext context) |
|||
{ |
|||
await _messageService.ErrorAsync(exception.Message); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling |
|||
{ |
|||
public class UserExceptionInformerContext |
|||
{ |
|||
[NotNull] |
|||
public Exception Exception { get; } |
|||
|
|||
public UserExceptionInformerContext(Exception exception) |
|||
{ |
|||
Exception = exception; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue