ASP.NET Core Web API Interview Question #129

How should validation errors differ from unexpected server errors?

Error Handling, Logging, Caching, Rate Limiting, CORS & Reliability Senior Advanced

Quick Interview Answer

Validation errors are expected client-facing failures and should identify invalid input with an appropriate 4xx status and useful field-level details. Unexpected exceptions indicate an unplanned server failure and normally result in a safe 500 response.

Detailed Explanation

Validation errors are expected client-facing failures and should identify invalid input with an appropriate 4xx status and useful field-level details. Unexpected exceptions indicate an unplanned server failure and normally result in a safe 500 response.

Production error responses should not expose stack traces, SQL messages, secret values, or internal implementation details.

Code Example

// Validation failure -> 400 with ValidationProblemDetails
// Unexpected exception -> 500 with safe ProblemDetails

return ValidationProblem(ModelState);