diff --git a/framework/Furion.Pure/FriendlyException/Oops.cs b/framework/Furion.Pure/FriendlyException/Oops.cs
index 9a136457df..b1f8dbac5b 100644
--- a/framework/Furion.Pure/FriendlyException/Oops.cs
+++ b/framework/Furion.Pure/FriendlyException/Oops.cs
@@ -148,25 +148,11 @@ namespace Furion.FriendlyException
{
if (action == null) throw new ArgumentNullException(nameof(action));
- // 不断重试
- while (true)
- {
- try
- {
- action(); return;
- }
- catch (Exception ex)
- {
- // 如果可重试次数小于或等于0,则终止重试
- if (--numRetries <= 0) throw;
-
- // 如果填写了 exceptionTypes 且异常类型不在 exceptionTypes 之内,则终止重试
- if (exceptionTypes != null && exceptionTypes.Length > 0 && !exceptionTypes.Any(u => u.IsAssignableFrom(ex.GetType()))) throw;
-
- // 如果可重试异常数大于 0,则间隔指定时间后继续执行
- if (retryTimeout > 0) Thread.Sleep(retryTimeout);
- }
- }
+ _ = Retry(() =>
+ {
+ action();
+ return 0;
+ }, numRetries, retryTimeout, exceptionTypes);
}
///
diff --git a/framework/Furion.Pure/Mvc/Extensions/MvcBuilderServiceCollectionExtensions.cs b/framework/Furion.Pure/Mvc/Extensions/MvcBuilderServiceCollectionExtensions.cs
index f0b81d7108..46b2b04117 100644
--- a/framework/Furion.Pure/Mvc/Extensions/MvcBuilderServiceCollectionExtensions.cs
+++ b/framework/Furion.Pure/Mvc/Extensions/MvcBuilderServiceCollectionExtensions.cs
@@ -25,21 +25,12 @@ namespace Microsoft.Extensions.DependencyInjection
///
///
///
- ///
+ ///
///
- public static IMvcBuilder AddMvcFilter(this IMvcBuilder mvcBuilder, Action extraConfigure = default)
+ public static IMvcBuilder AddMvcFilter(this IMvcBuilder mvcBuilder, Action configure = default)
where TFilter : IFilterMetadata
{
- // 非 Web 环境跳过注册
- if (App.WebHostEnvironment == default) return mvcBuilder;
-
- mvcBuilder.AddMvcOptions(options =>
- {
- options.Filters.Add();
-
- // 其他额外配置
- extraConfigure?.Invoke(options);
- });
+ mvcBuilder.Services.AddMvcFilter(configure);
return mvcBuilder;
}
@@ -49,9 +40,9 @@ namespace Microsoft.Extensions.DependencyInjection
///
///
///
- ///
+ ///
///
- public static IServiceCollection AddMvcFilter(this IServiceCollection services, Action extraConfigure = default)
+ public static IServiceCollection AddMvcFilter(this IServiceCollection services, Action configure = default)
where TFilter : IFilterMetadata
{
// 非 Web 环境跳过注册
@@ -62,7 +53,7 @@ namespace Microsoft.Extensions.DependencyInjection
options.Filters.Add();
// 其他额外配置
- extraConfigure?.Invoke(options);
+ configure?.Invoke(options);
});
return services;
diff --git a/framework/Furion/FriendlyException/Oops.cs b/framework/Furion/FriendlyException/Oops.cs
index 9a136457df..b1f8dbac5b 100644
--- a/framework/Furion/FriendlyException/Oops.cs
+++ b/framework/Furion/FriendlyException/Oops.cs
@@ -148,25 +148,11 @@ namespace Furion.FriendlyException
{
if (action == null) throw new ArgumentNullException(nameof(action));
- // 不断重试
- while (true)
- {
- try
- {
- action(); return;
- }
- catch (Exception ex)
- {
- // 如果可重试次数小于或等于0,则终止重试
- if (--numRetries <= 0) throw;
-
- // 如果填写了 exceptionTypes 且异常类型不在 exceptionTypes 之内,则终止重试
- if (exceptionTypes != null && exceptionTypes.Length > 0 && !exceptionTypes.Any(u => u.IsAssignableFrom(ex.GetType()))) throw;
-
- // 如果可重试异常数大于 0,则间隔指定时间后继续执行
- if (retryTimeout > 0) Thread.Sleep(retryTimeout);
- }
- }
+ _ = Retry(() =>
+ {
+ action();
+ return 0;
+ }, numRetries, retryTimeout, exceptionTypes);
}
///
diff --git a/framework/Furion/Mvc/Extensions/MvcBuilderServiceCollectionExtensions.cs b/framework/Furion/Mvc/Extensions/MvcBuilderServiceCollectionExtensions.cs
index f0b81d7108..46b2b04117 100644
--- a/framework/Furion/Mvc/Extensions/MvcBuilderServiceCollectionExtensions.cs
+++ b/framework/Furion/Mvc/Extensions/MvcBuilderServiceCollectionExtensions.cs
@@ -25,21 +25,12 @@ namespace Microsoft.Extensions.DependencyInjection
///
///
///
- ///
+ ///
///
- public static IMvcBuilder AddMvcFilter(this IMvcBuilder mvcBuilder, Action extraConfigure = default)
+ public static IMvcBuilder AddMvcFilter(this IMvcBuilder mvcBuilder, Action configure = default)
where TFilter : IFilterMetadata
{
- // 非 Web 环境跳过注册
- if (App.WebHostEnvironment == default) return mvcBuilder;
-
- mvcBuilder.AddMvcOptions(options =>
- {
- options.Filters.Add();
-
- // 其他额外配置
- extraConfigure?.Invoke(options);
- });
+ mvcBuilder.Services.AddMvcFilter(configure);
return mvcBuilder;
}
@@ -49,9 +40,9 @@ namespace Microsoft.Extensions.DependencyInjection
///
///
///
- ///
+ ///
///
- public static IServiceCollection AddMvcFilter(this IServiceCollection services, Action extraConfigure = default)
+ public static IServiceCollection AddMvcFilter(this IServiceCollection services, Action configure = default)
where TFilter : IFilterMetadata
{
// 非 Web 环境跳过注册
@@ -62,7 +53,7 @@ namespace Microsoft.Extensions.DependencyInjection
options.Filters.Add();
// 其他额外配置
- extraConfigure?.Invoke(options);
+ configure?.Invoke(options);
});
return services;
diff --git a/handbook/docs/friendly-exception.mdx b/handbook/docs/friendly-exception.mdx
index 1fd06a85ef..e5203310b0 100644
--- a/handbook/docs/friendly-exception.mdx
+++ b/handbook/docs/friendly-exception.mdx
@@ -296,6 +296,8 @@ throw Oops.Oh("哈哈哈哈");
throw Oops.Oh(errorCode: "x1001");
throw Oops.Oh(1000, typeof(Exception));
throw Oops.Oh(1000).StatusCode(400); // 设置错误码
+throw Oops.Bah("用户名或密码错误"); // 抛出业务异常,状态码为 400
+throw Oops.Bah(1000);
```
## 7.7 多个异常信息类型
diff --git a/handbook/docs/global/oops.mdx b/handbook/docs/global/oops.mdx
index 492f6ee71d..7fd5ad55d1 100644
--- a/handbook/docs/global/oops.mdx
+++ b/handbook/docs/global/oops.mdx
@@ -49,3 +49,10 @@ Oops.Retry(() => {
}, 3, 1000, typeof(ArgumentNullException));
```
+
+## 4.6 抛出业务异常
+
+```cs
+throw Oops.Bah("用户名或密码错误");
+throw Oops.Bah(1000);
+```
\ No newline at end of file
diff --git a/handbook/src/pages/index.js b/handbook/src/pages/index.js
index 7fbcb43137..b72220cb49 100644
--- a/handbook/src/pages/index.js
+++ b/handbook/src/pages/index.js
@@ -164,7 +164,7 @@ function Gitee() {
className={"furion-log-jiao" + (isDarkTheme ? " dark" : "")}
>
-
850,285
+
857,390
Downloads