Browse Source

统一异常信息返回

pull/862/head
李宏 2 years ago
parent
commit
2b0600db4f
  1. 11
      aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/Hubs/MessagesHub.cs
  2. 9
      aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/Messages/SignalRMessageSenderProvider.cs
  3. 9
      aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi.Authorization/LINGYUN/Abp/OpenApi/Authorization/OpenApiAuthorizationService.cs
  4. 10
      aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/PlatformManagementHttpApiHostModule.Configure.cs

11
aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/Hubs/MessagesHub.cs

@ -41,6 +41,9 @@ namespace LINGYUN.Abp.IM.SignalR.Hubs
protected IUserGroupStore UserGroupStore => LazyServiceProvider.LazyGetRequiredService<IUserGroupStore>(); protected IUserGroupStore UserGroupStore => LazyServiceProvider.LazyGetRequiredService<IUserGroupStore>();
protected AbpExceptionHandlingOptions ExceptionHandlingOptions => LazyServiceProvider.LazyGetRequiredService<IOptions<AbpExceptionHandlingOptions>>().Value;
public override async Task OnConnectedAsync() public override async Task OnConnectedAsync()
{ {
await base.OnConnectedAsync(); await base.OnConnectedAsync();
@ -167,8 +170,8 @@ namespace LINGYUN.Abp.IM.SignalR.Hubs
{ {
var errorInfo = ErrorInfoConverter.Convert(ex, options => var errorInfo = ErrorInfoConverter.Convert(ex, options =>
{ {
options.SendExceptionsDetailsToClients = false; options.SendExceptionsDetailsToClients = ExceptionHandlingOptions.SendExceptionsDetailsToClients;
options.SendStackTraceToClients = false; options.SendStackTraceToClients = ExceptionHandlingOptions.SendStackTraceToClients;
}); });
await SendMessageAsync( await SendMessageAsync(
@ -230,8 +233,8 @@ namespace LINGYUN.Abp.IM.SignalR.Hubs
{ {
var errorInfo = ErrorInfoConverter.Convert(ex, options => var errorInfo = ErrorInfoConverter.Convert(ex, options =>
{ {
options.SendExceptionsDetailsToClients = false; options.SendExceptionsDetailsToClients = ExceptionHandlingOptions.SendExceptionsDetailsToClients;
options.SendStackTraceToClients = false; options.SendStackTraceToClients = ExceptionHandlingOptions.SendStackTraceToClients;
}); });
if (!chatMessage.GroupId.IsNullOrWhiteSpace()) if (!chatMessage.GroupId.IsNullOrWhiteSpace())
{ {

9
aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/Messages/SignalRMessageSenderProvider.cs

@ -19,14 +19,17 @@ namespace LINGYUN.Abp.IM.SignalR.Messages
private readonly AbpIMSignalROptions _options; private readonly AbpIMSignalROptions _options;
private readonly IHubContext<MessagesHub> _hubContext; private readonly IHubContext<MessagesHub> _hubContext;
private readonly AbpExceptionHandlingOptions _exceptionHandlingOptions;
public SignalRMessageSenderProvider( public SignalRMessageSenderProvider(
IHubContext<MessagesHub> hubContext, IHubContext<MessagesHub> hubContext,
IAbpLazyServiceProvider serviceProvider, IAbpLazyServiceProvider serviceProvider,
IOptions<AbpIMSignalROptions> options) IOptions<AbpIMSignalROptions> options,
IOptions<AbpExceptionHandlingOptions> exceptionHandlingOptions)
: base(serviceProvider) : base(serviceProvider)
{ {
_options = options.Value; _options = options.Value;
_exceptionHandlingOptions = exceptionHandlingOptions.Value;
_hubContext = hubContext; _hubContext = hubContext;
} }
@ -99,8 +102,8 @@ namespace LINGYUN.Abp.IM.SignalR.Messages
{ {
var errorInfo = errorInfoConverter.Convert(ex, options => var errorInfo = errorInfoConverter.Convert(ex, options =>
{ {
options.SendExceptionsDetailsToClients = false; options.SendExceptionsDetailsToClients = _exceptionHandlingOptions.SendExceptionsDetailsToClients;
options.SendStackTraceToClients = false; options.SendStackTraceToClients = _exceptionHandlingOptions.SendStackTraceToClients;
}); });
if (!chatMessage.GroupId.IsNullOrWhiteSpace()) if (!chatMessage.GroupId.IsNullOrWhiteSpace())
{ {

9
aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi.Authorization/LINGYUN/Abp/OpenApi/Authorization/OpenApiAuthorizationService.cs

@ -26,17 +26,20 @@ namespace LINGYUN.Abp.OpenApi.Authorization
private readonly AbpOpenApiOptions _openApiOptions; private readonly AbpOpenApiOptions _openApiOptions;
private readonly ICurrentClient _currentClient; private readonly ICurrentClient _currentClient;
private readonly IWebClientInfoProvider _clientInfoProvider; private readonly IWebClientInfoProvider _clientInfoProvider;
private readonly AbpExceptionHandlingOptions _exceptionHandlingOptions;
public OpenApiAuthorizationService( public OpenApiAuthorizationService(
IAppKeyStore appKeyStore, IAppKeyStore appKeyStore,
ICurrentClient currentClient, ICurrentClient currentClient,
IWebClientInfoProvider clientInfoProvider, IWebClientInfoProvider clientInfoProvider,
IOptionsMonitor<AbpOpenApiOptions> options) IOptionsMonitor<AbpOpenApiOptions> options,
IOptions<AbpExceptionHandlingOptions> exceptionHandlingOptions)
{ {
_appKeyStore = appKeyStore; _appKeyStore = appKeyStore;
_currentClient = currentClient; _currentClient = currentClient;
_clientInfoProvider = clientInfoProvider; _clientInfoProvider = clientInfoProvider;
_openApiOptions = options.CurrentValue; _openApiOptions = options.CurrentValue;
_exceptionHandlingOptions = exceptionHandlingOptions.Value;
} }
public async virtual Task<bool> AuthorizeAsync(HttpContext httpContext) public async virtual Task<bool> AuthorizeAsync(HttpContext httpContext)
@ -177,8 +180,8 @@ namespace LINGYUN.Abp.OpenApi.Authorization
var errorInfoConverter = context.RequestServices.GetRequiredService<IExceptionToErrorInfoConverter>(); var errorInfoConverter = context.RequestServices.GetRequiredService<IExceptionToErrorInfoConverter>();
var errorInfo = errorInfoConverter.Convert(exception, options => var errorInfo = errorInfoConverter.Convert(exception, options =>
{ {
options.SendExceptionsDetailsToClients = false; options.SendExceptionsDetailsToClients = _exceptionHandlingOptions.SendExceptionsDetailsToClients;
options.SendStackTraceToClients = false; options.SendStackTraceToClients = _exceptionHandlingOptions.SendStackTraceToClients;
}); });
if (context.Request.CanAccept(MimeTypes.Application.Json) || if (context.Request.CanAccept(MimeTypes.Application.Json) ||

10
aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/PlatformManagementHttpApiHostModule.Configure.cs

@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Caching.StackExchangeRedis; using Microsoft.Extensions.Caching.StackExchangeRedis;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
using StackExchange.Redis; using StackExchange.Redis;
using System; using System;
@ -164,10 +165,11 @@ public partial class PlatformManagementHttpApiHostModule
}); });
Configure<Volo.Abp.AspNetCore.ExceptionHandling.AbpExceptionHandlingOptions>(options => Configure<Volo.Abp.AspNetCore.ExceptionHandling.AbpExceptionHandlingOptions>(options =>
{ {
// 是否发送错误详情 // 是否发送错误详情
options.SendExceptionsDetailsToClients = false; options.SendExceptionsDetailsToClients = true;
}); options.SendStackTraceToClients = true;
});
} }
private void ConfigureAuditing(IConfiguration configuration) private void ConfigureAuditing(IConfiguration configuration)

Loading…
Cancel
Save