File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
src/BootstrapBlazor/Components/ErrorLogger Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change 66using Microsoft . AspNetCore . Components . Rendering ;
77using Microsoft . Extensions . Configuration ;
88using Microsoft . Extensions . Logging ;
9+ using System . Reflection ;
910
1011namespace BootstrapBlazor . Components ;
1112
@@ -71,10 +72,8 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
7172 var ex = CurrentException ?? _exception ;
7273 if ( ex != null )
7374 {
74- _exception = null ;
75-
7675 // 处理自定义异常逻辑
77- if ( OnErrorHandleAsync != null )
76+ if ( OnErrorHandleAsync != null )
7877 {
7978 // 页面生命周期内异常直接调用这里
8079 _ = OnErrorHandleAsync ( Logger , ex ) ;
@@ -83,6 +82,9 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
8382
8483 // 渲染异常内容
8584 builder . AddContent ( 0 , ExceptionContent ( ex ) ) ;
85+
86+ // 重置 CurrentException
87+ ResetException ( ) ;
8688 }
8789 else
8890 {
@@ -91,6 +93,16 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
9193 }
9294 }
9395
96+ private PropertyInfo ? _currentExceptionPropertyInfo ;
97+
98+ private void ResetException ( )
99+ {
100+ _exception = null ;
101+
102+ _currentExceptionPropertyInfo ??= GetType ( ) . BaseType ! . GetProperty ( nameof ( CurrentException ) , BindingFlags . NonPublic | BindingFlags . Instance ) ;
103+ _currentExceptionPropertyInfo ? . SetValue ( this , null ) ;
104+ }
105+
94106 private Exception ? _exception = null ;
95107
96108 private RenderFragment < Exception > ExceptionContent => ex => builder =>
You can’t perform that action at this time.
0 commit comments