From 2f56c047a495bd76051590e16915719a8c57e7a8 Mon Sep 17 00:00:00 2001 From: Bradley Grainger Date: Thu, 9 May 2024 11:17:25 -0700 Subject: [PATCH] Convert Microsoft.AspNetCore exceptions to errors. This handles Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException, which can be thrown when hosting a ASP.NET Core API under Kestrel on Linux. See https://github.com/dotnet/aspnetcore/issues/20614 for the rationale behind the multiple namespaces. --- src/Facility.Core/Http/ServiceHttpHandler.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Facility.Core/Http/ServiceHttpHandler.cs b/src/Facility.Core/Http/ServiceHttpHandler.cs index 8ca62480..ab451647 100644 --- a/src/Facility.Core/Http/ServiceHttpHandler.cs +++ b/src/Facility.Core/Http/ServiceHttpHandler.cs @@ -205,11 +205,11 @@ protected override async Task SendAsync(HttpRequestMessage /// /// Called to determine if an error object should be created from an unexpected exception. /// - protected virtual bool ShouldCreateErrorFromException(Exception exception) - { - var exceptionTypeName = exception.GetType().FullName; - return exceptionTypeName != null && exceptionTypeName.StartsWith("System.Web.", StringComparison.Ordinal); - } + protected virtual bool ShouldCreateErrorFromException(Exception exception) => + exception.GetType().FullName is { } exceptionTypeName && ( + exceptionTypeName.StartsWith("Microsoft.AspNetCore.Http.", StringComparison.Ordinal) || + exceptionTypeName.StartsWith("Microsoft.AspNetCore.Server.", StringComparison.Ordinal) || + exceptionTypeName.StartsWith("System.Web.", StringComparison.Ordinal)); /// /// Called to create an error object from an unexpected exception.