Share via


ExceptionHandlerOptions Class

Definition

Options for configuring the ExceptionHandlerMiddleware.

public ref class ExceptionHandlerOptions
public class ExceptionHandlerOptions
type ExceptionHandlerOptions = class
Public Class ExceptionHandlerOptions
Inheritance
ExceptionHandlerOptions

Constructors

ExceptionHandlerOptions()

Properties

AllowStatusCode404Response

This value controls whether the ExceptionHandlerMiddleware should consider a response with a 404 status code to be a valid result of executing the ExceptionHandler. The default value is false and the middleware will consider 404 status codes to be an error on the server and will therefore rethrow the original exception.

CreateScopeForErrors

Gets or sets whether the handler needs to create a separate IServiceProvider scope and replace it on RequestServices when re-executing the request to handle an error.

ExceptionHandler

The RequestDelegate that will handle the exception. If this is not explicitly provided, the subsequent middleware pipeline will be used by default.

ExceptionHandlingPath

The path to the exception handling endpoint. This path will be used when executing the ExceptionHandler.

StatusCodeSelector

Gets or sets a delegate used to map an exception to an HTTP status code.

SuppressDiagnosticsCallback

Gets or sets a callback that can return true to suppress diagnostics in ExceptionHandlerMiddleware.

If SuppressDiagnosticsCallback is null, the default behavior is to suppress diagnostics if the exception was handled by an IExceptionHandler service instance registered in the DI container. To always record diagnostics for handled exceptions, set a callback that returns false.

This callback is only run if the exception was handled by the middleware. Unhandled exceptions and exceptions thrown after the response has started are always logged.

Suppressed diagnostics include:

  • Logging UnhandledException to ILogger.
  • Writing the Microsoft.AspNetCore.Diagnostics.HandledException event to EventSource.
  • Adding the error.type tag to the http.server.request.duration metric.

Applies to