From 363c64fa0a50754fae4e5370e829e7000b4bc72b Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Tue, 9 Mar 2021 17:08:09 +0800 Subject: [PATCH] Handle AbpRemoteCallException in DefaultExceptionToErrorInfoConverter --- .../ExceptionHandling/UserExceptionInformer.cs | 14 +++++++------- .../AbpExceptionHandlingOptions.cs | 0 .../DefaultExceptionToErrorInfoConverter.cs | 6 ++++++ .../Volo/Abp/Http/Client/AbpRemoteCallException.cs | 0 4 files changed, 13 insertions(+), 7 deletions(-) rename framework/src/{Volo.Abp.AspNetCore => Volo.Abp.ExceptionHandling}/Volo/Abp/AspNetCore/ExceptionHandling/AbpExceptionHandlingOptions.cs (100%) rename framework/src/{Volo.Abp.Http.Client => Volo.Abp.ExceptionHandling}/Volo/Abp/Http/Client/AbpRemoteCallException.cs (100%) diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/UserExceptionInformer.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/UserExceptionInformer.cs index ca3a2be9c5..87af9b92b7 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/UserExceptionInformer.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/UserExceptionInformer.cs @@ -1,6 +1,7 @@ using System; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.Components.Messages; using Volo.Abp.AspNetCore.ExceptionHandling; using Volo.Abp.DependencyInjection; @@ -15,12 +16,16 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling protected IUiMessageService MessageService { get; } protected IExceptionToErrorInfoConverter ExceptionToErrorInfoConverter { get; } + protected AbpExceptionHandlingOptions Options { get; } + public UserExceptionInformer( IUiMessageService messageService, - IExceptionToErrorInfoConverter exceptionToErrorInfoConverter) + IExceptionToErrorInfoConverter exceptionToErrorInfoConverter, + IOptions options) { MessageService = messageService; ExceptionToErrorInfoConverter = exceptionToErrorInfoConverter; + Options = options.Value; Logger = NullLogger.Instance; } @@ -41,12 +46,7 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling protected virtual RemoteServiceErrorInfo GetErrorInfo(UserExceptionInformerContext context) { - if (context.Exception is AbpRemoteCallException remoteCallException) - { - return remoteCallException.Error; - } - - return ExceptionToErrorInfoConverter.Convert(context.Exception, false); + return ExceptionToErrorInfoConverter.Convert(context.Exception, Options.SendExceptionsDetailsToClients); } } } diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/AbpExceptionHandlingOptions.cs b/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/AspNetCore/ExceptionHandling/AbpExceptionHandlingOptions.cs similarity index 100% rename from framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/AbpExceptionHandlingOptions.cs rename to framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/AspNetCore/ExceptionHandling/AbpExceptionHandlingOptions.cs diff --git a/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/AspNetCore/ExceptionHandling/DefaultExceptionToErrorInfoConverter.cs b/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/AspNetCore/ExceptionHandling/DefaultExceptionToErrorInfoConverter.cs index 6c0c8ef193..7d6da59e81 100644 --- a/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/AspNetCore/ExceptionHandling/DefaultExceptionToErrorInfoConverter.cs +++ b/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/AspNetCore/ExceptionHandling/DefaultExceptionToErrorInfoConverter.cs @@ -11,6 +11,7 @@ using Volo.Abp.Domain.Entities; using Volo.Abp.ExceptionHandling; using Volo.Abp.ExceptionHandling.Localization; using Volo.Abp.Http; +using Volo.Abp.Http.Client; using Volo.Abp.Localization; using Volo.Abp.Localization.ExceptionHandling; using Volo.Abp.Validation; @@ -62,6 +63,11 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling return CreateEntityNotFoundError(exception as EntityNotFoundException); } + if (exception is AbpRemoteCallException remoteCallException) + { + return remoteCallException.Error; + } + var errorInfo = new RemoteServiceErrorInfo(); if (exception is IUserFriendlyException) diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/AbpRemoteCallException.cs b/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/Http/Client/AbpRemoteCallException.cs similarity index 100% rename from framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/AbpRemoteCallException.cs rename to framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/Http/Client/AbpRemoteCallException.cs