Enhanced global features interceptor

pull/8131/head
maliming 5 years ago
parent fd1af333de
commit 2347b37534

@ -1,22 +0,0 @@
using System;
using Volo.Abp.ExceptionHandling;
namespace Volo.Abp.GlobalFeatures
{
public class AbpGlobalFeatureNotEnableException : AbpException, IHasErrorCode
{
public string Code { get; }
public AbpGlobalFeatureNotEnableException(string message = null, string code = null, Exception innerException = null)
: base(message, innerException)
{
Code = code;
}
public AbpGlobalFeatureNotEnableException WithData(string name, object value)
{
Data[name] = value;
return this;
}
}
}

@ -0,0 +1,23 @@
using System;
using Volo.Abp.ExceptionHandling;
namespace Volo.Abp.GlobalFeatures
{
[Serializable]
public class AbpGlobalFeatureNotEnabledException : AbpException, IHasErrorCode
{
public string Code { get; }
public AbpGlobalFeatureNotEnabledException(string message = null, string code = null, Exception innerException = null)
: base(message, innerException)
{
Code = code;
}
public AbpGlobalFeatureNotEnabledException WithData(string name, object value)
{
Data[name] = value;
return this;
}
}
}

@ -5,9 +5,9 @@ namespace Volo.Abp.GlobalFeatures
{
public static class GlobalFeatureHelper
{
public static bool IsGlobalFeatureEnabled(Type controllerType, out RequiresGlobalFeatureAttribute attribute)
public static bool IsGlobalFeatureEnabled(Type type, out RequiresGlobalFeatureAttribute attribute)
{
attribute = ReflectionHelper.GetSingleAttributeOrDefault<RequiresGlobalFeatureAttribute>(controllerType);
attribute = ReflectionHelper.GetSingleAttributeOrDefault<RequiresGlobalFeatureAttribute>(type);
return attribute == null || GlobalFeatureManager.Instance.IsEnabled(attribute.GetFeatureName());
}
}

@ -17,7 +17,7 @@ namespace Volo.Abp.GlobalFeatures
if (!GlobalFeatureHelper.IsGlobalFeatureEnabled(invocation.TargetObject.GetType(), out var attribute))
{
throw new AbpGlobalFeatureNotEnableException(code: AbpGlobalFeatureErrorCodes.GlobalFeatureIsNotEnabled)
throw new AbpGlobalFeatureNotEnabledException(code: AbpGlobalFeatureErrorCodes.GlobalFeatureIsNotEnabled)
.WithData("ServiceName", invocation.TargetObject.GetType().FullName)
.WithData("GlobalFeatureName", attribute.Name);
}

@ -19,7 +19,7 @@ namespace Volo.Abp.GlobalFeatures
{
using (CultureHelper.Use("zh-Hans"))
{
var exception = new AbpGlobalFeatureNotEnableException(code: AbpGlobalFeatureErrorCodes.GlobalFeatureIsNotEnabled)
var exception = new AbpGlobalFeatureNotEnabledException(code: AbpGlobalFeatureErrorCodes.GlobalFeatureIsNotEnabled)
.WithData("ServiceName", "MyService")
.WithData("GlobalFeatureName", "TestFeature");;
var errorInfo = _exceptionToErrorInfoConverter.Convert(exception, false);

@ -20,7 +20,7 @@ namespace Volo.Abp.GlobalFeatures
[Fact]
public async Task Interceptor_Test()
{
var ex = await Assert.ThrowsAsync<AbpGlobalFeatureNotEnableException>(async () =>
var ex = await Assert.ThrowsAsync<AbpGlobalFeatureNotEnabledException>(async () =>
{
await _testAppServiceV1.TestMethod();
});

Loading…
Cancel
Save