fix(GlobalExceptionHandlerMiddleware): add await

This commit is contained in:
tekh 2025-07-30 17:00:03 +02:00
parent 0554cbf7bc
commit 56cb3e247f
2 changed files with 7 additions and 3 deletions

View File

@ -38,6 +38,10 @@
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'"> <ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.5" /> <PackageReference Include="Microsoft.Extensions.Options" Version="9.0.5" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.3.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.7" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\DigitalData.Core.Exceptions\DigitalData.Core.Exceptions.csproj" /> <ProjectReference Include="..\DigitalData.Core.Exceptions\DigitalData.Core.Exceptions.csproj" />

View File

@ -42,11 +42,11 @@ public class GlobalExceptionHandlerMiddleware
} }
catch (Exception ex) catch (Exception ex)
{ {
if(ex.GetType() == typeof(Exception)) if(ex.GetType() == typeof(Exception) && _options?.DefaultHandler is not null)
_options?.DefaultHandler?.HandleExceptionAsync.Invoke(context, ex, _logger); await _options.DefaultHandler.HandleExceptionAsync(context, ex, _logger);
if (_options?.Handlers.TryGetValue(ex.GetType(), out var handler) ?? false) if (_options?.Handlers.TryGetValue(ex.GetType(), out var handler) ?? false)
handler?.HandleExceptionAsync.Invoke(context, ex, _logger); await handler.HandleExceptionAsync(context, ex, _logger);
} }
} }
} }