stac-fastapi icon indicating copy to clipboard operation
stac-fastapi copied to clipboard

Unclear error message for failed response model validation

Open drnextgis opened this issue 1 year ago • 3 comments

When response model validation is enabled, the API returns an unclear error message that doesn't specify which property failed validation. For example:

{"code":"AttributeError","description":"'int' object has no attribute 'startswith'"}

In this case, the issue was caused by the asset href containing a number instead of a string.

drnextgis avatar Sep 12 '24 14:09 drnextgis

@drnextgis can you be a bit more verbose. which version of stac-fastapi, which backend, which endpoint?

vincentsarago avatar Sep 12 '24 15:09 vincentsarago

Oh I see, you're saying we should try to make the error message a bit more verbose 😓

I guess https://github.com/stac-utils/stac-fastapi/blob/main/stac_fastapi/api/stac_fastapi/api/errors.py#L49-L97 needs to be updated

vincentsarago avatar Sep 12 '24 15:09 vincentsarago

Exactly, having the name of the property that failed validation would be extremely helpful.

drnextgis avatar Sep 13 '24 13:09 drnextgis

FYI we do need to change https://github.com/stac-utils/stac-fastapi/blob/main/stac_fastapi/api/stac_fastapi/api/errors.py#L87-L93 because it returns validation error message in a weird (non-JSON) form:

[{
  'type': 'string_too_short',
  'loc': ('body', 'id'),
  'msg': 'String should have at least 1 character',
  'input': '',
  'ctx': {'min_length': 1}
}]

ref: https://fastapi.tiangolo.com/tutorial/handling-errors/?h=requestvalidationerror#use-the-requestvalidationerror-body

vincentsarago avatar Dec 16 '24 16:12 vincentsarago

Looks like there is a ValidationError.json 👌

j08lue avatar Dec 16 '24 16:12 j08lue