public class SampleProblemDetailsWriter : IProblemDetailsWriter { // Indicates that only responses with StatusCode == 400 // are handled by this writer. All others are // handled by different registered writers if available. public bool CanWrite(ProblemDetailsContext context) => context.HttpContext.Response.StatusCode == 400; public ValueTask WriteAsync(ProblemDetailsContext context) { // Additional customizations. // Write to the response. var response = context.HttpContext.Response; return new ValueTask(response.WriteAsJsonAsync(context.ProblemDetails)); } }