PostHog / drf-exceptions-hog

Standardized and easy-to-parse API error responses for Django REST Framework (DRF).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can we have all errors in a single response?

duciito opened this issue · comments

Hello, I'm trying to figure out if this is included (or if planned for later on) where we get all errors in a single JSON response.
For example, if I were to send a bad POST request with two blank fields, I'd only get an error for one of them:

{
    "type": "validation_error",
    "code": "blank",
    "detail": "This field may not be blank.",
    "attr": "FIELD_ONE"
}

How can we get something like:

errors: [
    {
        "type": "validation_error",
        "code": "blank",
        "detail": "This field may not be blank.",
        "attr": "FIELD_ONE"
    },
    {
        "type": "validation_error",
        "code": "blank",
        "detail": "This field may not be blank.",
        "attr": "FIELD_TWO"
    }
]

It really helps with sign up forms for example, since the user gets to see all failing fields the first time, instead of fixing them one by one every failing request.

Hey! That's a cool idea, but I'm sure if it would work since I think DRF raises an error at first sight of a deserialization issue – though @paolodamico may know more.

Yeah... I only suggested that because the default DRF exception handling returns a list of all de/serialization errors.

Hey @duciito! That's a great point, I'll give it some thought over the weekend and we'll get back to you.

Any changes on this topic??

Hey @davidcode43w! I'm really sorry about the delay here, we've been swamped with other stuff and haven't had a time to jump at this, will probably need a couple more weeks before I can push an improvement here but any contributions are highly welcomed!