Code Monkey home page Code Monkey logo

Comments (3)

stevenj avatar stevenj commented on June 26, 2024 1

FastAPI returns a Json body that looks like this:

{
    "detail": [
        {
            "loc": [
                "path",
                "item_id"
            ],
            "msg": "value is not a valid integer",
            "type": "type_error.integer"
        }
    ]
}

I find this super handy because the response tells you all your validation errors in the request, not just the first one it hit.
It would be good if the bad_request_handler got a vec of validation errors rather than a single error. This would then allow one to produce a similar response.

from poem.

sunli829 avatar sunli829 commented on June 26, 2024

You can define a bad_request_handler to create a response for the error, refer to this example to implement it. 🙂

When the request parsing fails, it may be of these types.

from poem.

root-talis avatar root-talis commented on June 26, 2024

I'd love to have the ability to list all validation errors in a formalized manner. This is a future I widely use in other frameworks to tell the client exactly why the request is bad. Comes in handy in frontend - to paint invalid form fields red and add hints to them.

Maybe add a validation_errors_handler, similiar to bad_request_handler, that would accept a vec of validation errors and return a #[derive(Object)] struct?

Should I issue a separate feature request for this?

from poem.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.