Class JsonErrorDetailsOptions
Configures JSON error responses and exception normalization for a JSON error-details middleware registration.
Inherited Members
Namespace: NanoRoute
Assembly: NanoRoute.dll
Syntax
public sealed class JsonErrorDetailsOptions : ExceptionHandlingOptions
Remarks
AddJsonErrorDetails<TBuilder>(TBuilder, Action<JsonErrorDetailsOptions>) snapshots these options when the middleware is registered. Because this type derives from ExceptionHandlingOptions, the same callback can configure both JSON error rendering and the internally registered exception handler.
Examples
builder.AddJsonErrorDetails(options =>
{
options.PopulateErrorInfo = true;
options.Map<NotSupportedException>
(
static ex => new HttpRequestException("Not supported", ex, HttpStatusCode.BadRequest)
);
});
Constructors
JsonErrorDetailsOptions()
Declaration
public JsonErrorDetailsOptions()
Properties
ErrorDetailsTypeInfo
Gets or sets the JSON serialization metadata used for ErrorDetails responses.
Declaration
public JsonTypeInfo<ErrorDetails> ErrorDetailsTypeInfo { get; set; }
Property Value
| Type | Description |
|---|---|
| JsonTypeInfo<ErrorDetails> |
Remarks
Replace this value to use custom source-generated metadata, property naming, converters, or other serializer behavior for the error payload.
Examples
builder.AddJsonErrorDetails(options =>
{
options.ErrorDetailsTypeInfo = MyJsonContext.Default.ErrorDetails;
});
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when the assigned value is null. |
PopulateErrorInfo
Gets or sets a value indicating whether developer-facing diagnostic details should be included in JSON error responses.
Declaration
public bool PopulateErrorInfo { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
Diagnostic details may contain exception messages or stack traces. Keep this value false for production responses unless the caller is trusted to see those details.
Examples
builder.AddJsonErrorDetails(options =>
{
options.PopulateErrorInfo = true;
});