openaq / openaq-api-v2

OpenAQ API
https://api.openaq.org
43 stars 9 forks source link

better parse pydantic validation errors #300

Open russbiggs opened 1 year ago

russbiggs commented 1 year ago

specifically in v3 we have must more validation set for query parameters but with pydantic v2 the behavior has changes in how its returns the validation error when serving a 422 e.g.

https://api.openaq.org/v3/locations?limit=100000

will return:

{
    "detail": [
        {
            "type": "less_than_equal",
             "loc": [
                 "query",
                 "limit"
              ],
             "msg": "Input should be less than or equal to 1000",
             "input": 100000,
             "ctx": {
                 "le": 1000
              },
             "url": "https://errors.pydantic.dev/2.1.2/v/less_than_equal"
       }
   ]
}

Most of the content is informative but coudl likely be better parsed and displayed for users in a way that does not expose the underlying pydantic implementation