diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/DefaultExceptionWrapHandler.cs b/aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/DefaultExceptionWrapHandler.cs index 1e1a668cb..b933eeeb4 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/DefaultExceptionWrapHandler.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/DefaultExceptionWrapHandler.cs @@ -28,6 +28,12 @@ namespace LINGYUN.Abp.Wrapper // 没有处理的异常代码统一用配置代码处理 if (context.ErrorInfo.Code.IsNullOrWhiteSpace()) { + if (context.StatusCode.HasValue) + { + context.WithCode(context.StatusCode.ToString()); + return; + } + // TODO: 先从TttpStatusCodeFinder中查找 var wrapperOptions = context.ServiceProvider.GetRequiredService>().Value; context.WithCode(wrapperOptions.CodeWithUnhandled); } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/ExceptionWrapContext.cs b/aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/ExceptionWrapContext.cs index 3d9ec339d..a1aa51084 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/ExceptionWrapContext.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/ExceptionWrapContext.cs @@ -1,4 +1,5 @@ using System; +using System.Net; using Volo.Abp.Http; namespace LINGYUN.Abp.Wrapper @@ -8,14 +9,17 @@ namespace LINGYUN.Abp.Wrapper public Exception Exception { get; } public IServiceProvider ServiceProvider { get; } public RemoteServiceErrorInfo ErrorInfo { get; } + public HttpStatusCode? StatusCode { get; set; } public ExceptionWrapContext( Exception exception, RemoteServiceErrorInfo errorInfo, - IServiceProvider serviceProvider) + IServiceProvider serviceProvider, + HttpStatusCode? statusCode = null) { Exception = exception; ErrorInfo = errorInfo; ServiceProvider = serviceProvider; + StatusCode = statusCode; } public ExceptionWrapContext WithCode(string code) diff --git a/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionPageWrapResultFilter.cs b/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionPageWrapResultFilter.cs index 881fe66a8..aba15e9e3 100644 --- a/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionPageWrapResultFilter.cs +++ b/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionPageWrapResultFilter.cs @@ -48,8 +48,13 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper.ExceptionHandling await context.GetRequiredService().NotifyAsync(new ExceptionNotificationContext(context.Exception)); + var statusCodFinder = context.GetRequiredService(); var exceptionWrapHandler = context.GetRequiredService(); - var exceptionWrapContext = new ExceptionWrapContext(context.Exception, remoteServiceErrorInfo, context.HttpContext.RequestServices); + var exceptionWrapContext = new ExceptionWrapContext( + context.Exception, + remoteServiceErrorInfo, + context.HttpContext.RequestServices, + statusCodFinder.GetStatusCode(context.HttpContext, context.Exception)); exceptionWrapHandler.CreateFor(exceptionWrapContext).Wrap(exceptionWrapContext); var wrapResult = new WrapResult( exceptionWrapContext.ErrorInfo.Code, diff --git a/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionWrapResultFilter.cs b/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionWrapResultFilter.cs index 1c5584e3f..c734625a7 100644 --- a/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionWrapResultFilter.cs +++ b/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionWrapResultFilter.cs @@ -51,8 +51,13 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper.ExceptionHandling await context.GetRequiredService().NotifyAsync(new ExceptionNotificationContext(context.Exception)); + var statusCodFinder = context.GetRequiredService(); var exceptionWrapHandler = context.GetRequiredService(); - var exceptionWrapContext = new ExceptionWrapContext(context.Exception, remoteServiceErrorInfo, context.HttpContext.RequestServices); + var exceptionWrapContext = new ExceptionWrapContext( + context.Exception, + remoteServiceErrorInfo, + context.HttpContext.RequestServices, + statusCodFinder.GetStatusCode(context.HttpContext, context.Exception)); exceptionWrapHandler.CreateFor(exceptionWrapContext).Wrap(exceptionWrapContext); var wrapResult = new WrapResult( exceptionWrapContext.ErrorInfo.Code, diff --git a/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/Wraping/ActionResultWrapperFactory.cs b/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/Wraping/ActionResultWrapperFactory.cs index 8db57a15f..c7bd2159b 100644 --- a/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/Wraping/ActionResultWrapperFactory.cs +++ b/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/Wraping/ActionResultWrapperFactory.cs @@ -10,29 +10,16 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper.Wraping { Check.NotNull(context, nameof(context)); - switch (context) + return context switch { - case ResultExecutingContext resultExecutingContext when resultExecutingContext.Result is ObjectResult: - return new ObjectActionResultWrapper(); - - case ResultExecutingContext resultExecutingContext when resultExecutingContext.Result is JsonResult: - return new JsonActionResultWrapper(); - - case ResultExecutingContext resultExecutingContext when resultExecutingContext.Result is EmptyResult: - return new EmptyActionResultWrapper(); - - case PageHandlerExecutedContext pageHandlerExecutedContext when pageHandlerExecutedContext.Result is ObjectResult: - return new ObjectActionResultWrapper(); - - case PageHandlerExecutedContext pageHandlerExecutedContext when pageHandlerExecutedContext.Result is JsonResult: - return new JsonActionResultWrapper(); - - case PageHandlerExecutedContext pageHandlerExecutedContext when pageHandlerExecutedContext.Result is EmptyResult: - return new EmptyActionResultWrapper(); - - default: - return new NullActionResultWrapper(); - } + ResultExecutingContext resultExecutingContext when resultExecutingContext.Result is ObjectResult => new ObjectActionResultWrapper(), + ResultExecutingContext resultExecutingContext when resultExecutingContext.Result is JsonResult => new JsonActionResultWrapper(), + ResultExecutingContext resultExecutingContext when resultExecutingContext.Result is EmptyResult => new EmptyActionResultWrapper(), + PageHandlerExecutedContext pageHandlerExecutedContext when pageHandlerExecutedContext.Result is ObjectResult => new ObjectActionResultWrapper(), + PageHandlerExecutedContext pageHandlerExecutedContext when pageHandlerExecutedContext.Result is JsonResult => new JsonActionResultWrapper(), + PageHandlerExecutedContext pageHandlerExecutedContext when pageHandlerExecutedContext.Result is EmptyResult => new EmptyActionResultWrapper(), + _ => new NullActionResultWrapper(), + }; } } } diff --git a/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi.Authorization/LINGYUN/Abp/OpenApi/Authorization/OpenApiAuthorizationService.cs b/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi.Authorization/LINGYUN/Abp/OpenApi/Authorization/OpenApiAuthorizationService.cs index 7ed53477d..0a5d80753 100644 --- a/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi.Authorization/LINGYUN/Abp/OpenApi/Authorization/OpenApiAuthorizationService.cs +++ b/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi.Authorization/LINGYUN/Abp/OpenApi/Authorization/OpenApiAuthorizationService.cs @@ -205,10 +205,11 @@ namespace LINGYUN.Abp.OpenApi.Authorization await context.Response.WriteAsync(errorInfo.Message); } - private static string CalculationSignature(string url, string appKey, IDictionary queryDictionary) + private static string CalculationSignature(string url, string appSecret, IDictionary queryDictionary) { + queryDictionary.TryAdd("appSecret", appSecret); var queryString = BuildQuery(queryDictionary); - var encodeUrl = UrlEncode(string.Concat(url, "?", queryString, appKey)); + var encodeUrl = UrlEncode(string.Concat(url, "?", queryString)); return encodeUrl.ToMd5(); } @@ -216,7 +217,7 @@ namespace LINGYUN.Abp.OpenApi.Authorization private static string BuildQuery(IDictionary queryStringDictionary) { StringBuilder sb = new StringBuilder(); - foreach (var queryString in queryStringDictionary) + foreach (var queryString in queryStringDictionary.OrderBy(q => q.Key)) { sb.Append(queryString.Key) .Append('=') @@ -229,7 +230,7 @@ namespace LINGYUN.Abp.OpenApi.Authorization private static string UrlEncode(string str) { - return HttpUtility.UrlEncode(str); + return HttpUtility.UrlEncode(str, Encoding.UTF8).ToUpper(); } } }