fastapi-keycloak
fastapi-keycloak copied to clipboard
Error on "get_user" when user doesn't exists
Wen i try to search for a user that doesn't exist, an error occurs:
{
"detail": "list index out of range"
}
Occurs in the line below, as the API returns a empty array.
https://github.com/code-specialist/fastapi-keycloak/blob/28f5f7bf18c25c8677202ad2f1d3c2437763a58d/fastapi_keycloak/api.py#L833
A suggestion would be to check before instantiating the object:
response_json = response.json()
return KeycloakUser(**response_json[0]) if len(response_json) else None
This way the API will allow me to check if a user exists in keycloak. What do you think?
Hey @fabiothz. Nice catch, this really shouldn't happen.
Personally, I would expect an error to be thrown here. Something like a UserNotFound exception. This would be the most explicit and customizable behavior I can think of. I would wait for @JonasScholl opinion on this
I believe this can now be closed! @fabiothz Are you still experiencing the issue with the latest release?