What is ProblemDetails, and why use it for API errors?
Quick Answer
ProblemDetails is a standardised JSON error format (RFC 7807 / 9457) with fields like type, title, status, detail, instance. Using it everywhere means every client parses errors the same way instead of guessing at ad-hoc shapes. [ApiController] already returns it for validation failures.
ProblemDetails is the IETF standard shape for an HTTP API error — a JSON object with title, status, detail, a type URI, and room for custom fields. The value is consistency: a client writes one error handler instead of dealing with a different JSON structure per endpoint. ASP.NET Core already emits it for model-validation 400s, and with AddProblemDetails plus the exception handler middleware you get it for unhandled exceptions too. I always add a trace id to the payload so when a user sends me the error I can find the exact request in the logs, and I make sure production responses don't include stack traces.
builder.Services.AddProblemDetails();plusapp.UseExceptionHandler()gives consistent problem responses for unhandled exceptions.- Add a
traceId/ correlation id extension member so a user's error report maps to your logs. ValidationProblemDetailsextends it with a per-fielderrorsdictionary.- Don't leak stack traces or internal messages in
detailin production.