Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Set ProblemDetails status field during ObjectResult formatting #8118

Merged
merged 1 commit into from
Jul 20, 2018

Conversation

khellang
Copy link
Contributor

I just think it's convenient to have the status field present.

This allows you to do

var problem = new ValidationProblemDetails(ModelState);
return new UnprocessableEntityObjectResult(problem);

or

var problem = new ValidationProblemDetails(ModelState);
return new BadRequestObjectResult(problem);

And have the correct status code reflected in the problem details response.

One question is; should the result even override an existing status value?

The RFC states:

Generators MUST use the same status code in the actual HTTP response, to assure that generic HTTP software that does not understand this format still behaves correctly.

@pranavkm
Copy link
Contributor

should the result even override an existing status value?

MVC generally avoids overwriting explicitly specified values with implicit \ inferred values. The current code seems fine as is.

@pranavkm pranavkm merged commit 53930af into aspnet:release/2.2 Jul 20, 2018
@pranavkm
Copy link
Contributor

Thanks for the PR!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants