Skip to content

Route handlers throw System.Text.Json.JsonReader exception for requests with invalid JSON body rather than returning 422 #36499

@DamianEdwards

Description

@DamianEdwards

Consider the following minimal API:

app.MapPost("/todos", (Todo todo) =>
{
    // Do something with todo here...
});

class Todo
{
    public string? Text { get; set; }
}

Sending a request with invalid JSON body but that is otherwise well-formed results in a 500 response, due to the underlying JSON reader exception not being handled by the framework:

image

We should likely be returning a 422 Unprocessable Entity instead.

Metadata

Metadata

Assignees

Labels

Priority:1Work that is critical for the release, but we could probably ship withoutarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-actionsController-like actions for endpoint routingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions