Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DamianEdwards opened this issue Sep 14, 2021 · 1 comment · Fixed by #36589
Assignees
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-minimal-actions Controller-like actions for endpoint routing old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels Priority:1 Work that is critical for the release, but we could probably ship without
Milestone

Comments

@DamianEdwards
Copy link
Member

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.

@DamianEdwards DamianEdwards added the feature-minimal-actions Controller-like actions for endpoint routing label Sep 14, 2021
@rafikiassumani-msft rafikiassumani-msft added the old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Sep 14, 2021
@rafikiassumani-msft rafikiassumani-msft added this to the 6.0-rc2 milestone Sep 14, 2021
@rafikiassumani-msft rafikiassumani-msft added the Priority:1 Work that is critical for the release, but we could probably ship without label Sep 14, 2021
@DamianEdwards
Copy link
Member Author

MVC (with ApiController) responds with a 400 in this scenario (the Problem Details is due to the convention applied to ApiController instances):

image

@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
@amcasey amcasey added the area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc label Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-minimal-actions Controller-like actions for endpoint routing old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels Priority:1 Work that is critical for the release, but we could probably ship without
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants