What is ProblemDetails (RFC 7807/9457), and how does ASP.NET Core support it for standardized error responses?
Short answer
ProblemDetails is a standardized JSON format for HTTP API error responses, including fields like type, title, status, detail, and instance, providing a consistent, machine-and-human-readable error structure across an entire API (and interoperably across different APIs following…
Advertisement
AModel answer
ProblemDetails is a standardized JSON format for HTTP API error responses, including fields like type, title, status, detail, and instance, providing a consistent, machine-and-human-readable error structure across an entire API (and interoperably across different APIs following the same standard). ASP.NET Core has built-in support via Results.Problem(), AddProblemDetails(), and automatic ProblemDetails generation for validation failures and unhandled exceptions when configured, reducing the need to hand-roll a custom error response shape.
builder.Services.AddProblemDetails(); // enables automatic ProblemDetails for errors
app.UseExceptionHandler(); // now produces RFC-compliant ProblemDetails responses automatically
// Manual usage:
return Results.Problem(title: "Insufficient stock", statusCode: 409, detail: "Only 2 units remaining");Real-world example
A public API adopts ProblemDetails universally so that third-party integrators consuming errors from any endpoint (validation failures, business rule violations, unhandled exceptions) always see the same consistent, well-documented JSON error shape.
Likely follow-ups
- What are the standard vs extension members of the ProblemDetails format?
- How do you add custom extension fields to a ProblemDetails response?
Related topics