Browse Source

Merge pull request #416 from colinin/4.4.2

fix(wapper): IHttpExceptionStatusCodeFinder 优先级高于用户配置.
pull/426/head
yx lin 4 years ago
committed by GitHub
parent
commit
048940fbaf
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/DefaultExceptionWrapHandler.cs
  2. 6
      aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/ExceptionWrapContext.cs
  3. 7
      aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionPageWrapResultFilter.cs
  4. 7
      aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionWrapResultFilter.cs
  5. 31
      aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/Wraping/ActionResultWrapperFactory.cs
  6. 9
      aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi.Authorization/LINGYUN/Abp/OpenApi/Authorization/OpenApiAuthorizationService.cs

6
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.ErrorInfo.Code.IsNullOrWhiteSpace())
{ {
if (context.StatusCode.HasValue)
{
context.WithCode(context.StatusCode.ToString());
return;
}
// TODO: 先从TttpStatusCodeFinder中查找
var wrapperOptions = context.ServiceProvider.GetRequiredService<IOptions<AbpWrapperOptions>>().Value; var wrapperOptions = context.ServiceProvider.GetRequiredService<IOptions<AbpWrapperOptions>>().Value;
context.WithCode(wrapperOptions.CodeWithUnhandled); context.WithCode(wrapperOptions.CodeWithUnhandled);
} }

6
aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/ExceptionWrapContext.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Net;
using Volo.Abp.Http; using Volo.Abp.Http;
namespace LINGYUN.Abp.Wrapper namespace LINGYUN.Abp.Wrapper
@ -8,14 +9,17 @@ namespace LINGYUN.Abp.Wrapper
public Exception Exception { get; } public Exception Exception { get; }
public IServiceProvider ServiceProvider { get; } public IServiceProvider ServiceProvider { get; }
public RemoteServiceErrorInfo ErrorInfo { get; } public RemoteServiceErrorInfo ErrorInfo { get; }
public HttpStatusCode? StatusCode { get; set; }
public ExceptionWrapContext( public ExceptionWrapContext(
Exception exception, Exception exception,
RemoteServiceErrorInfo errorInfo, RemoteServiceErrorInfo errorInfo,
IServiceProvider serviceProvider) IServiceProvider serviceProvider,
HttpStatusCode? statusCode = null)
{ {
Exception = exception; Exception = exception;
ErrorInfo = errorInfo; ErrorInfo = errorInfo;
ServiceProvider = serviceProvider; ServiceProvider = serviceProvider;
StatusCode = statusCode;
} }
public ExceptionWrapContext WithCode(string code) public ExceptionWrapContext WithCode(string code)

7
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<IExceptionNotifier>().NotifyAsync(new ExceptionNotificationContext(context.Exception)); await context.GetRequiredService<IExceptionNotifier>().NotifyAsync(new ExceptionNotificationContext(context.Exception));
var statusCodFinder = context.GetRequiredService<IHttpExceptionStatusCodeFinder>();
var exceptionWrapHandler = context.GetRequiredService<IExceptionWrapHandlerFactory>(); var exceptionWrapHandler = context.GetRequiredService<IExceptionWrapHandlerFactory>();
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); exceptionWrapHandler.CreateFor(exceptionWrapContext).Wrap(exceptionWrapContext);
var wrapResult = new WrapResult( var wrapResult = new WrapResult(
exceptionWrapContext.ErrorInfo.Code, exceptionWrapContext.ErrorInfo.Code,

7
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<IExceptionNotifier>().NotifyAsync(new ExceptionNotificationContext(context.Exception)); await context.GetRequiredService<IExceptionNotifier>().NotifyAsync(new ExceptionNotificationContext(context.Exception));
var statusCodFinder = context.GetRequiredService<IHttpExceptionStatusCodeFinder>();
var exceptionWrapHandler = context.GetRequiredService<IExceptionWrapHandlerFactory>(); var exceptionWrapHandler = context.GetRequiredService<IExceptionWrapHandlerFactory>();
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); exceptionWrapHandler.CreateFor(exceptionWrapContext).Wrap(exceptionWrapContext);
var wrapResult = new WrapResult( var wrapResult = new WrapResult(
exceptionWrapContext.ErrorInfo.Code, exceptionWrapContext.ErrorInfo.Code,

31
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)); Check.NotNull(context, nameof(context));
switch (context) return context switch
{ {
case ResultExecutingContext resultExecutingContext when resultExecutingContext.Result is ObjectResult: ResultExecutingContext resultExecutingContext when resultExecutingContext.Result is ObjectResult => new ObjectActionResultWrapper(),
return new ObjectActionResultWrapper(); ResultExecutingContext resultExecutingContext when resultExecutingContext.Result is JsonResult => new JsonActionResultWrapper(),
ResultExecutingContext resultExecutingContext when resultExecutingContext.Result is EmptyResult => new EmptyActionResultWrapper(),
case ResultExecutingContext resultExecutingContext when resultExecutingContext.Result is JsonResult: PageHandlerExecutedContext pageHandlerExecutedContext when pageHandlerExecutedContext.Result is ObjectResult => new ObjectActionResultWrapper(),
return new JsonActionResultWrapper(); PageHandlerExecutedContext pageHandlerExecutedContext when pageHandlerExecutedContext.Result is JsonResult => new JsonActionResultWrapper(),
PageHandlerExecutedContext pageHandlerExecutedContext when pageHandlerExecutedContext.Result is EmptyResult => new EmptyActionResultWrapper(),
case ResultExecutingContext resultExecutingContext when resultExecutingContext.Result is EmptyResult: _ => new NullActionResultWrapper(),
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();
}
} }
} }
} }

9
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); await context.Response.WriteAsync(errorInfo.Message);
} }
private static string CalculationSignature(string url, string appKey, IDictionary<string, string> queryDictionary) private static string CalculationSignature(string url, string appSecret, IDictionary<string, string> queryDictionary)
{ {
queryDictionary.TryAdd("appSecret", appSecret);
var queryString = BuildQuery(queryDictionary); var queryString = BuildQuery(queryDictionary);
var encodeUrl = UrlEncode(string.Concat(url, "?", queryString, appKey)); var encodeUrl = UrlEncode(string.Concat(url, "?", queryString));
return encodeUrl.ToMd5(); return encodeUrl.ToMd5();
} }
@ -216,7 +217,7 @@ namespace LINGYUN.Abp.OpenApi.Authorization
private static string BuildQuery(IDictionary<string, string> queryStringDictionary) private static string BuildQuery(IDictionary<string, string> queryStringDictionary)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
foreach (var queryString in queryStringDictionary) foreach (var queryString in queryStringDictionary.OrderBy(q => q.Key))
{ {
sb.Append(queryString.Key) sb.Append(queryString.Key)
.Append('=') .Append('=')
@ -229,7 +230,7 @@ namespace LINGYUN.Abp.OpenApi.Authorization
private static string UrlEncode(string str) private static string UrlEncode(string str)
{ {
return HttpUtility.UrlEncode(str); return HttpUtility.UrlEncode(str, Encoding.UTF8).ToUpper();
} }
} }
} }

Loading…
Cancel
Save