Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear error message for failed response model validation #750

Open
drnextgis opened this issue Sep 12, 2024 · 5 comments
Open

Unclear error message for failed response model validation #750

drnextgis opened this issue Sep 12, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@drnextgis
Copy link
Contributor

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.

@vincentsarago
Copy link
Member

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

@vincentsarago
Copy link
Member

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

@drnextgis
Copy link
Contributor Author

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

@vincentsarago
Copy link
Member

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 vincentsarago added the bug Something isn't working label Dec 16, 2024
@j08lue
Copy link

j08lue commented Dec 16, 2024

Looks like there is a ValidationError.json 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants