Error handling for ASP.NET Core APIs — exception middleware, ProblemDetails,
94
90%
Does it follow best practices?
Impact
100%
1.13xAverage score across 5 eval scenarios
Passed
No known issues
A healthcare SaaS company is integrating their patient registration API with several hospital information systems (HIS). The HIS vendors have all implemented clients that understand RFC 7807 Problem Details responses — they look for the errors dictionary inside the response body to display field-level validation messages to clinical staff (e.g. "Date of birth is required", "NHS number must be 10 digits").
The problem: the current API uses the default ASP.NET Core model validation behaviour, which returns a response shaped differently from the structured error format the exception handler produces. When a nurse submits a form with a missing required field, the mobile terminal shows a parsing error instead of the specific field message. The HIS integration team has explicitly asked that validation failures use the same RFC 7807 format as all other errors, with a consistent title and the errors map populated with field names and messages.
The API uses Data Annotations ([Required], [MaxLength], [RegularExpression]) on its request models. You do not need to switch validation libraries — just ensure the response format matches what the HIS clients expect.
Produce the following files in your working directory:
Program.cs — startup configuration including the validation error response customisationPatientRegistrationRequest.cs — a request model with at least four fields using data annotation validation attributesPatientsController.cs — a controller with a POST endpoint at /api/patients that accepts the request modelvalidation_design.md — a short explanation (3–5 sentences) of how the validation response is shaped, what the title field contains, and which Content-Type is returnedDo NOT add manual validation logic inside the controller action — rely on ASP.NET Core's automatic model validation.
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
skills
aspnet-error-handling
verifiers