AspNetCore.Docs.Samples/fundamentals/middleware/problem-details-service/SampleProblemDetailsWriter.cs

18 lines
637 B
C#
Raw Permalink Normal View History

2022-10-12 07:05:14 +08:00
public class SampleProblemDetailsWriter : IProblemDetailsWriter
{
2022-10-12 07:32:50 +08:00
// Indicates that only responses with StatusCode == 400
// are handled by this writer. All others are
// handled by different registered writers if available.
2022-10-12 07:05:14 +08:00
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));
2022-10-12 07:05:14 +08:00
}
}