-
Notifications
You must be signed in to change notification settings - Fork 109
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
ProblemDetails middleware ignore errors from ActionFilterAttribute #2
Comments
Hi! The assumption is that if Someone else, in this case, is MVC's object result executor. It has already set the content type and written to the body by the time the problem details middleware is reached on the way out. This means it's too late for the middleware to write anything. In this case it shouldn't matter whether the middleware or MVC's filter writes the response, since it's a If you really need the MW to handle the response, you can throw a |
Thanks @khellang Was my fault, I've configured ApiBehaviorOptions and I don't need the ActionFilter and works together: public static IServiceCollection AddProblemDetails(this IServiceCollection services) =>
services.Configure<ApiBehaviorOptions>(options =>
{
options.InvalidModelStateResponseFactory = context =>
{
var problemDetails = new ValidationProblemDetails(context.ModelState)
{
Instance = context.HttpContext.Request.Path,
Status = StatusCodes.Status400BadRequest,
Type = $"https://httpstatuses.com/400",
Detail = "Please refer to the errors property for additional details."
};
return new BadRequestObjectResult(problemDetails)
{
ContentTypes = { "application/problem+json", "application/problem+xml" }
};
};
}); I have to say Hellang.Middleware.ProblemDetails is awesome, great work!!! Regards! |
Nice. Glad you got it working! Incidentally, I just sent a PR to MVC to copy over the result status code to the problem details object, so from 2.2, you don't have to set it explicitly; aspnet/Mvc#8118 |
Hi,
I usually try to manage model validation in an ActionFilterAttribute:
But ProblemDetails middleware ignore errors from this ActionFilterAttribute:
I understand the first two conditionals in the method, but not the logic that decides the last:
Regards!
The text was updated successfully, but these errors were encountered: