From 26e1edcabe7876156714f71c78d7a01ad3280525 Mon Sep 17 00:00:00 2001 From: John Luo Date: Mon, 22 Mar 2021 21:42:37 -0700 Subject: [PATCH 1/8] Add helpful log message and exception when exception handler returns 404 --- .../src/DiagnosticsLoggerExtensions.cs | 5 ++++- .../ExceptionHandlerMiddleware.cs | 4 +++- .../test/UnitTests/ExceptionHandlerTest.cs | 17 ++++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs b/src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs index 1a812f8d1579..4c1ff3a6c4f1 100644 --- a/src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs +++ b/src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Diagnostics @@ -20,7 +21,9 @@ internal static class DiagnosticsLoggerExtensions LoggerMessage.Define(LogLevel.Error, new EventId(3, "Exception"), "An exception was thrown attempting to execute the error handler."); private static readonly Action _errorHandlerNotFound = - LoggerMessage.Define(LogLevel.Warning, new EventId(4, "HandlerNotFound"), "No exception handler was found, rethrowing original exception."); + LoggerMessage.Define(LogLevel.Warning, new EventId(4, "HandlerNotFound"), $"The exception handler configured on {nameof(ExceptionHandlerOptions)} produced a 404 status response. " + + $"An InvalidOperationException containing the original exception will be thrown since this is often due to a misconfigured {nameof(ExceptionHandlerOptions.ExceptionHandlingPath)}. " + + $"If the exception handler should be allowed to return 404 status responses, {nameof(ExceptionHandlerOptions.AllowStatusCode404Response)} must be set to true."); // DeveloperExceptionPageMiddleware private static readonly Action _responseStartedErrorPageMiddleware = diff --git a/src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerMiddleware.cs b/src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerMiddleware.cs index 11cfac7f19ce..bd458b5a0510 100644 --- a/src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerMiddleware.cs +++ b/src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerMiddleware.cs @@ -143,6 +143,8 @@ private async Task HandleException(HttpContext context, ExceptionDispatchInfo ed } _logger.ErrorHandlerNotFound(); + + edi = ExceptionDispatchInfo.Capture(new InvalidOperationException($"No exception handler was found, see inner exception for details of original exception. If an exception should not be thrown for 404 responses, set {nameof(ExceptionHandlerOptions.AllowStatusCode404Response)} to true.", edi.SourceException)); } catch (Exception ex2) { @@ -154,7 +156,7 @@ private async Task HandleException(HttpContext context, ExceptionDispatchInfo ed context.Request.Path = originalPath; } - edi.Throw(); // Re-throw the original if we couldn't handle it + edi.Throw(); // Re-throw wrapped exception or the original if we couldn't handle it } private static void ClearHttpContext(HttpContext context) diff --git a/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs b/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs index 5e2f38f7d13f..d1b07dd434a7 100644 --- a/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs +++ b/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs @@ -469,7 +469,7 @@ public void UsingExceptionHandler_ThrowsAnException_WhenExceptionHandlingPathNot } [Fact] - public async Task ExceptionHandlerNotFound_RethrowsOriginalError() + public async Task ExceptionHandlerNotFound_ThrowsIOEWithOriginalError() { var sink = new TestSink(TestSink.EnableWithTypeName); var loggerFactory = new TestLoggerFactory(sink, enabled: true); @@ -500,9 +500,14 @@ public async Task ExceptionHandlerNotFound_RethrowsOriginalError() httpContext.Response.StatusCode = StatusCodes.Status500InternalServerError; } - // The original exception is thrown + // Invalid operation exception Assert.NotNull(exception); - Assert.Equal("Something bad happened.", exception.Message); + Assert.Equal($"No exception handler was found, see inner exception for details of original exception. If an exception should not be thrown for 404 responses, set {nameof(ExceptionHandlerOptions.AllowStatusCode404Response)} to true.", exception.Message); + + // The original exception is inner exception + Assert.NotNull(exception.InnerException); + Assert.IsType(exception.InnerException); + Assert.Equal("Something bad happened.", exception.InnerException.Message); }); @@ -520,7 +525,7 @@ public async Task ExceptionHandlerNotFound_RethrowsOriginalError() { innerAppBuilder.Run(httpContext => { - throw new InvalidOperationException("Something bad happened."); + throw new ApplicationException("Something bad happened."); }); }); }); @@ -539,7 +544,9 @@ public async Task ExceptionHandlerNotFound_RethrowsOriginalError() Assert.Contains(sink.Writes, w => w.LogLevel == LogLevel.Warning && w.EventId == 4 - && w.Message == "No exception handler was found, rethrowing original exception."); + && w.Message == $"The exception handler configured on {nameof(ExceptionHandlerOptions)} produced a 404 status response. " + + $"An InvalidOperationException containing the original exception will be thrown since this is often due to a misconfigured {nameof(ExceptionHandlerOptions.ExceptionHandlingPath)}. " + + $"If the exception handler should be allowed to return 404 status responses, {nameof(ExceptionHandlerOptions.AllowStatusCode404Response)} must be set to true."); } [Fact] From 8cd7750220759eefbccc19a0dc67f9d1b47a0ebb Mon Sep 17 00:00:00 2001 From: John Luo Date: Tue, 23 Mar 2021 18:05:26 -0700 Subject: [PATCH 2/8] Update src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs Co-authored-by: Chris Ross --- src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs b/src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs index 4c1ff3a6c4f1..a04f24db4095 100644 --- a/src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs +++ b/src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs @@ -23,7 +23,7 @@ internal static class DiagnosticsLoggerExtensions private static readonly Action _errorHandlerNotFound = LoggerMessage.Define(LogLevel.Warning, new EventId(4, "HandlerNotFound"), $"The exception handler configured on {nameof(ExceptionHandlerOptions)} produced a 404 status response. " + $"An InvalidOperationException containing the original exception will be thrown since this is often due to a misconfigured {nameof(ExceptionHandlerOptions.ExceptionHandlingPath)}. " + - $"If the exception handler should be allowed to return 404 status responses, {nameof(ExceptionHandlerOptions.AllowStatusCode404Response)} must be set to true."); + $"If the exception handler is expected to return 404 status responses then set {nameof(ExceptionHandlerOptions.AllowStatusCode404Response)} to true."); // DeveloperExceptionPageMiddleware private static readonly Action _responseStartedErrorPageMiddleware = From e5f812d955efd809a1535536a2f8439ac1119193 Mon Sep 17 00:00:00 2001 From: John Luo Date: Tue, 23 Mar 2021 18:05:37 -0700 Subject: [PATCH 3/8] Update src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs Co-authored-by: Chris Ross --- .../Diagnostics/test/UnitTests/ExceptionHandlerTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs b/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs index d1b07dd434a7..90f55345299b 100644 --- a/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs +++ b/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs @@ -502,7 +502,7 @@ public async Task ExceptionHandlerNotFound_ThrowsIOEWithOriginalError() // Invalid operation exception Assert.NotNull(exception); - Assert.Equal($"No exception handler was found, see inner exception for details of original exception. If an exception should not be thrown for 404 responses, set {nameof(ExceptionHandlerOptions.AllowStatusCode404Response)} to true.", exception.Message); + Assert.Equal("No exception handler was found, see inner exception for details of original exception. If an exception should not be thrown for 404 responses, set AllowStatusCode404Response to true.", exception.Message); // The original exception is inner exception Assert.NotNull(exception.InnerException); From a5d213008c822af3528b1569742ec338734e9723 Mon Sep 17 00:00:00 2001 From: John Luo Date: Tue, 23 Mar 2021 18:49:52 -0700 Subject: [PATCH 4/8] nit --- .../Diagnostics/test/UnitTests/ExceptionHandlerTest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs b/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs index 90f55345299b..005cc58d282f 100644 --- a/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs +++ b/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs @@ -544,9 +544,9 @@ public async Task ExceptionHandlerNotFound_ThrowsIOEWithOriginalError() Assert.Contains(sink.Writes, w => w.LogLevel == LogLevel.Warning && w.EventId == 4 - && w.Message == $"The exception handler configured on {nameof(ExceptionHandlerOptions)} produced a 404 status response. " + - $"An InvalidOperationException containing the original exception will be thrown since this is often due to a misconfigured {nameof(ExceptionHandlerOptions.ExceptionHandlingPath)}. " + - $"If the exception handler should be allowed to return 404 status responses, {nameof(ExceptionHandlerOptions.AllowStatusCode404Response)} must be set to true."); + && w.Message == $"The exception handler configured on ExceptionHandlerOptions produced a 404 status response. " + + $"An InvalidOperationException containing the original exception will be thrown since this is often due to a misconfigured ExceptionHandlingPath. " + + $"If the exception handler should be allowed to return 404 status responses, AllowStatusCode404Response must be set to true."); } [Fact] From 00544612d3db24ad8bc1e84e9a4291d4ea9a8375 Mon Sep 17 00:00:00 2001 From: John Luo Date: Wed, 24 Mar 2021 13:04:03 -0700 Subject: [PATCH 5/8] fb --- .../Diagnostics/src/DiagnosticsLoggerExtensions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs b/src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs index a04f24db4095..58fcce475f41 100644 --- a/src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs +++ b/src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs @@ -21,9 +21,9 @@ internal static class DiagnosticsLoggerExtensions LoggerMessage.Define(LogLevel.Error, new EventId(3, "Exception"), "An exception was thrown attempting to execute the error handler."); private static readonly Action _errorHandlerNotFound = - LoggerMessage.Define(LogLevel.Warning, new EventId(4, "HandlerNotFound"), $"The exception handler configured on {nameof(ExceptionHandlerOptions)} produced a 404 status response. " + - $"An InvalidOperationException containing the original exception will be thrown since this is often due to a misconfigured {nameof(ExceptionHandlerOptions.ExceptionHandlingPath)}. " + - $"If the exception handler is expected to return 404 status responses then set {nameof(ExceptionHandlerOptions.AllowStatusCode404Response)} to true."); + LoggerMessage.Define(LogLevel.Warning, new EventId(4, "HandlerNotFound"), $"The exception handler configured on ExceptionHandlerOptions produced a 404 status response. " + + $"An InvalidOperationException containing the original exception will be thrown since this is often due to a misconfigured ExceptionHandlerOptions.ExceptionHandlingPath. " + + $"If the exception handler is expected to return 404 status responses then set ExceptionHandlerOptions.AllowStatusCode404Response to true."); // DeveloperExceptionPageMiddleware private static readonly Action _responseStartedErrorPageMiddleware = From 9df746cb179cad414735f7682b6f217b1c62a31b Mon Sep 17 00:00:00 2001 From: John Luo Date: Wed, 24 Mar 2021 17:20:25 -0700 Subject: [PATCH 6/8] Update src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs Co-authored-by: Chris Ross --- .../Diagnostics/src/DiagnosticsLoggerExtensions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs b/src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs index 58fcce475f41..612c46f3fbcd 100644 --- a/src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs +++ b/src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs @@ -21,9 +21,9 @@ internal static class DiagnosticsLoggerExtensions LoggerMessage.Define(LogLevel.Error, new EventId(3, "Exception"), "An exception was thrown attempting to execute the error handler."); private static readonly Action _errorHandlerNotFound = - LoggerMessage.Define(LogLevel.Warning, new EventId(4, "HandlerNotFound"), $"The exception handler configured on ExceptionHandlerOptions produced a 404 status response. " + - $"An InvalidOperationException containing the original exception will be thrown since this is often due to a misconfigured ExceptionHandlerOptions.ExceptionHandlingPath. " + - $"If the exception handler is expected to return 404 status responses then set ExceptionHandlerOptions.AllowStatusCode404Response to true."); + LoggerMessage.Define(LogLevel.Warning, new EventId(4, "HandlerNotFound"), "The exception handler configured on ExceptionHandlerOptions produced a 404 status response. " + + "An InvalidOperationException containing the original exception will be thrown since this is often due to a misconfigured ExceptionHandlerOptions.ExceptionHandlingPath. " + + "If the exception handler is expected to return 404 status responses then set ExceptionHandlerOptions.AllowStatusCode404Response to true."); // DeveloperExceptionPageMiddleware private static readonly Action _responseStartedErrorPageMiddleware = From 3583be7efff597d0427dae00e881ed70fd0ae632 Mon Sep 17 00:00:00 2001 From: John Luo Date: Wed, 31 Mar 2021 13:11:52 -0700 Subject: [PATCH 7/8] Remove log and rely on exception --- .../src/DiagnosticsLoggerExtensions.cs | 10 ---------- .../ExceptionHandlerMiddleware.cs | 6 +++--- .../test/UnitTests/ExceptionHandlerTest.cs | 18 +++--------------- 3 files changed, 6 insertions(+), 28 deletions(-) diff --git a/src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs b/src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs index 612c46f3fbcd..210e28e768c7 100644 --- a/src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs +++ b/src/Middleware/Diagnostics/src/DiagnosticsLoggerExtensions.cs @@ -20,11 +20,6 @@ internal static class DiagnosticsLoggerExtensions private static readonly Action _errorHandlerException = LoggerMessage.Define(LogLevel.Error, new EventId(3, "Exception"), "An exception was thrown attempting to execute the error handler."); - private static readonly Action _errorHandlerNotFound = - LoggerMessage.Define(LogLevel.Warning, new EventId(4, "HandlerNotFound"), "The exception handler configured on ExceptionHandlerOptions produced a 404 status response. " + - "An InvalidOperationException containing the original exception will be thrown since this is often due to a misconfigured ExceptionHandlerOptions.ExceptionHandlingPath. " + - "If the exception handler is expected to return 404 status responses then set ExceptionHandlerOptions.AllowStatusCode404Response to true."); - // DeveloperExceptionPageMiddleware private static readonly Action _responseStartedErrorPageMiddleware = LoggerMessage.Define(LogLevel.Warning, new EventId(2, "ResponseStarted"), "The response has already started, the error page middleware will not be executed."); @@ -47,11 +42,6 @@ public static void ErrorHandlerException(this ILogger logger, Exception exceptio _errorHandlerException(logger, exception); } - public static void ErrorHandlerNotFound(this ILogger logger) - { - _errorHandlerNotFound(logger, null); - } - public static void ResponseStartedErrorPageMiddleware(this ILogger logger) { _responseStartedErrorPageMiddleware(logger, null); diff --git a/src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerMiddleware.cs b/src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerMiddleware.cs index bd458b5a0510..e50b16b0021b 100644 --- a/src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerMiddleware.cs +++ b/src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerMiddleware.cs @@ -142,9 +142,9 @@ private async Task HandleException(HttpContext context, ExceptionDispatchInfo ed return; } - _logger.ErrorHandlerNotFound(); - - edi = ExceptionDispatchInfo.Capture(new InvalidOperationException($"No exception handler was found, see inner exception for details of original exception. If an exception should not be thrown for 404 responses, set {nameof(ExceptionHandlerOptions.AllowStatusCode404Response)} to true.", edi.SourceException)); + edi = ExceptionDispatchInfo.Capture(new InvalidOperationException($"The exception handler configured on {nameof(ExceptionHandlerOptions)} produced a 404 status response. " + + $"An {nameof(InvalidOperationException)} containing the original exception will be thrown since this is often due to a misconfigured {nameof(ExceptionHandlerOptions.ExceptionHandlingPath)}. " + + $"If the exception handler is expected to return 404 status responses then set {nameof(ExceptionHandlerOptions.AllowStatusCode404Response)} to true.", edi.SourceException)); } catch (Exception ex2) { diff --git a/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs b/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs index 005cc58d282f..a3d460a2693e 100644 --- a/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs +++ b/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs @@ -471,18 +471,11 @@ public void UsingExceptionHandler_ThrowsAnException_WhenExceptionHandlingPathNot [Fact] public async Task ExceptionHandlerNotFound_ThrowsIOEWithOriginalError() { - var sink = new TestSink(TestSink.EnableWithTypeName); - var loggerFactory = new TestLoggerFactory(sink, enabled: true); - using var host = new HostBuilder() .ConfigureWebHost(webHostBuilder => { webHostBuilder .UseTestServer() - .ConfigureServices(services => - { - services.AddSingleton(loggerFactory); - }) .Configure(app => { app.Use(async (httpContext, next) => @@ -502,7 +495,9 @@ public async Task ExceptionHandlerNotFound_ThrowsIOEWithOriginalError() // Invalid operation exception Assert.NotNull(exception); - Assert.Equal("No exception handler was found, see inner exception for details of original exception. If an exception should not be thrown for 404 responses, set AllowStatusCode404Response to true.", exception.Message); + Assert.Equal("The exception handler configured on ExceptionHandlerOptions produced a 404 status response. " + + "An InvalidOperationException containing the original exception will be thrown since this is often due to a misconfigured ExceptionHandlingPath. " + + "If the exception handler is expected to return 404 status responses then set AllowStatusCode404Response to true.", exception.Message); // The original exception is inner exception Assert.NotNull(exception.InnerException); @@ -540,13 +535,6 @@ public async Task ExceptionHandlerNotFound_ThrowsIOEWithOriginalError() Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); Assert.Equal(string.Empty, await response.Content.ReadAsStringAsync()); } - - Assert.Contains(sink.Writes, w => - w.LogLevel == LogLevel.Warning - && w.EventId == 4 - && w.Message == $"The exception handler configured on ExceptionHandlerOptions produced a 404 status response. " + - $"An InvalidOperationException containing the original exception will be thrown since this is often due to a misconfigured ExceptionHandlingPath. " + - $"If the exception handler should be allowed to return 404 status responses, AllowStatusCode404Response must be set to true."); } [Fact] From 39f4259655333ada407385687e1165fb4dbbcc05 Mon Sep 17 00:00:00 2001 From: John Luo Date: Wed, 31 Mar 2021 13:37:03 -0700 Subject: [PATCH 8/8] nit --- .../src/ExceptionHandler/ExceptionHandlerMiddleware.cs | 4 ++-- .../Diagnostics/test/UnitTests/ExceptionHandlerTest.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerMiddleware.cs b/src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerMiddleware.cs index e50b16b0021b..a21a634daf11 100644 --- a/src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerMiddleware.cs +++ b/src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerMiddleware.cs @@ -143,8 +143,8 @@ private async Task HandleException(HttpContext context, ExceptionDispatchInfo ed } edi = ExceptionDispatchInfo.Capture(new InvalidOperationException($"The exception handler configured on {nameof(ExceptionHandlerOptions)} produced a 404 status response. " + - $"An {nameof(InvalidOperationException)} containing the original exception will be thrown since this is often due to a misconfigured {nameof(ExceptionHandlerOptions.ExceptionHandlingPath)}. " + - $"If the exception handler is expected to return 404 status responses then set {nameof(ExceptionHandlerOptions.AllowStatusCode404Response)} to true.", edi.SourceException)); + $"This {nameof(InvalidOperationException)} containing the original exception was thrown since this is often due to a misconfigured {nameof(ExceptionHandlerOptions.ExceptionHandlingPath)}. " + + $"If the exception handler is expected to return 404 status responses then set {nameof(ExceptionHandlerOptions.AllowStatusCode404Response)} to true.", edi.SourceException)); } catch (Exception ex2) { diff --git a/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs b/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs index a3d460a2693e..a7790bb145f6 100644 --- a/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs +++ b/src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs @@ -496,7 +496,7 @@ public async Task ExceptionHandlerNotFound_ThrowsIOEWithOriginalError() // Invalid operation exception Assert.NotNull(exception); Assert.Equal("The exception handler configured on ExceptionHandlerOptions produced a 404 status response. " + - "An InvalidOperationException containing the original exception will be thrown since this is often due to a misconfigured ExceptionHandlingPath. " + + "This InvalidOperationException containing the original exception was thrown since this is often due to a misconfigured ExceptionHandlingPath. " + "If the exception handler is expected to return 404 status responses then set AllowStatusCode404Response to true.", exception.Message); // The original exception is inner exception