Skip to content

[Question] Is there a way to properly emulate InvalidModelStateResponseFactory in minimal apis? #57337

Open

Description

Hi.

When trying to migrate some existing endpoints to minimal apis, I discovered that is not as easy as in controllers to change the behaviour of a binding error (and I wanted to return the same responses...).

In controllers you have the InvalidModelStateResponseFactory which you can use to modify the response to these invalid requests:

image

When trying to do the same in minimal apis, I have found two ways, filter or middleware.

With a filter you get the arguments but you don't know why the binding failed (required parameter not provided vs. not parsable) and the arguments have default values (like 0 but you passed a string)

With a middleware you can catch the exception but you only get a message like "Failed to bind parameter "long id" from "this has to be a long"."

So the question is, is there another way so I can return the same response as before when using controllers but using minimal apis?

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions