ASP.NET Core Interview Question #160
What is Problem Details in ASP.NET Core?
Logging, Error Handling & Background Services Mid-Level Intermediate
Quick Interview Answer
Problem Details is a standardized JSON format for describing HTTP API errors. It commonly contains fields such as type, title, status, detail, and instance, with optional extension properties.
Detailed Explanation
Problem Details is a standardized JSON format for describing HTTP API errors. It commonly contains fields such as type, title, status, detail, and instance, with optional extension properties.
Using a consistent error representation makes APIs easier for clients to consume and avoids inventing a different error schema for every endpoint.
ASP.NET Core provides ProblemDetails support that can be integrated with exception handling and API error responses.
Code Example
builder.Services.AddProblemDetails();
app.MapGet("/products/{id:int}", (int id) =>
{
return Results.Problem(
title: "Product unavailable",
detail: $"Product {id} could not be found.",
statusCode: StatusCodes.Status404NotFound);
});